LibreOffice Module forms (master) 1
Time.cxx
Go to the documentation of this file.
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 "Time.hxx"
21#include <property.hxx>
22#include <services.hxx>
24#include <tools/debug.hxx>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/sdbc/DataType.hpp>
27#include <com/sun/star/util/DateTime.hpp>
28#include <com/sun/star/form/FormComponentType.hpp>
29
30using namespace dbtools;
31
32namespace frm
33{
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::sdb;
38using namespace ::com::sun::star::sdbc;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::container;
41using namespace ::com::sun::star::form;
42using namespace ::com::sun::star::util;
43using namespace ::com::sun::star::awt;
44using namespace ::com::sun::star::io;
45using namespace ::com::sun::star::lang;
46
47
48//=
49
50OTimeControl::OTimeControl(const Reference<XComponentContext>& _rxFactory)
51 :OBoundControl(_rxFactory, VCL_CONTROL_TIMEFIELD)
52{
53}
54
55
56Sequence<Type> OTimeControl::_getTypes()
57{
58 return OBoundControl::_getTypes();
59}
60
61
62css::uno::Sequence<OUString> SAL_CALL OTimeControl::getSupportedServiceNames()
63{
64 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
65 aSupported.realloc(aSupported.getLength() + 2);
66
67 OUString*pArray = aSupported.getArray();
68 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_TIMEFIELD;
69 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_TIMEFIELD;
70 return aSupported;
71}
72
73
74//= OTimeModel
75
76// XServiceInfo
77
78css::uno::Sequence<OUString> SAL_CALL OTimeModel::getSupportedServiceNames()
79{
80 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
81
82 sal_Int32 nOldLen = aSupported.getLength();
83 aSupported.realloc( nOldLen + 9 );
84 OUString* pStoreTo = aSupported.getArray() + nOldLen;
85
86 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
87 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
88 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
89
92
93 *pStoreTo++ = FRM_SUN_COMPONENT_TIMEFIELD;
95 *pStoreTo++ = BINDABLE_DATABASE_TIME_FIELD;
96
97 *pStoreTo++ = FRM_COMPONENT_TIMEFIELD;
98
99 return aSupported;
100}
101
102
103Sequence<Type> OTimeModel::_getTypes()
104{
105 return OBoundControlModel::_getTypes();
106}
107
108
109OTimeModel::OTimeModel(const Reference<XComponentContext>& _rxFactory)
111 FRM_SUN_CONTROL_TIMEFIELD, true, true)
112 // use the old control name for compatibility reasons
113 , OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
114 , m_bDateTimeField(false)
115{
116 m_nClassId = FormComponentType::TIMEFIELD;
118
119 setAggregateSet(m_xAggregateFastSet, getOriginalHandle(PROPERTY_ID_TIMEFORMAT));
120}
121
122
123OTimeModel::OTimeModel(const OTimeModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
124 : OEditBaseModel(_pOriginal, _rxFactory)
125 , OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
126 , m_bDateTimeField(false)
127{
128 setAggregateSet( m_xAggregateFastSet, getOriginalHandle( PROPERTY_ID_TIMEFORMAT ) );
129}
130
131
133{
134 setAggregateSet(Reference< XFastPropertySet >(), -1);
135}
136
137// XCloneable
138
139css::uno::Reference< css::util::XCloneable > SAL_CALL OTimeModel::createClone()
140{
142 pClone->clonedFrom(this);
143 return pClone;
144}
145
146
147OUString SAL_CALL OTimeModel::getServiceName()
148{
149 return FRM_COMPONENT_TIMEFIELD; // old (non-sun) name for compatibility !
150}
151
152// XPropertySet
153
154void OTimeModel::describeFixedProperties( Sequence< Property >& _rProps ) const
155{
157 sal_Int32 nOldCount = _rProps.getLength();
158 _rProps.realloc( nOldCount + 4);
159 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
160 *pProperties++ = css::beans::Property(PROPERTY_DEFAULT_TIME, PROPERTY_ID_DEFAULT_TIME, cppu::UnoType<util::Time>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT | css::beans::PropertyAttribute::MAYBEVOID);
161 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
162 *pProperties++ = css::beans::Property(PROPERTY_FORMATKEY, PROPERTY_ID_FORMATKEY, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::TRANSIENT);
164 css::beans::PropertyAttribute::READONLY | css::beans::PropertyAttribute::TRANSIENT);
165 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
166}
167
168
169void SAL_CALL OTimeModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle ) const
170{
171 switch (_nHandle)
172 {
175 break;
177 _rValue <<= getFormatsSupplier();
178 break;
179 default:
180 OEditBaseModel::getFastPropertyValue(_rValue, _nHandle);
181 break;
182 }
183}
184
185
186sal_Bool SAL_CALL OTimeModel::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
187 sal_Int32 _nHandle, const Any& _rValue )
188{
189 if (PROPERTY_ID_FORMATKEY == _nHandle)
190 return convertFormatKeyPropertyValue(_rConvertedValue, _rOldValue, _rValue);
191 else
192 return OEditBaseModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue );
193}
194
195
196void SAL_CALL OTimeModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue)
197{
198 if (PROPERTY_ID_FORMATKEY == _nHandle)
200 else
202}
203
204// XLoadListener
205
206void OTimeModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
207{
209 Reference<XPropertySet> xField = getField();
210 if (!xField.is())
211 return;
212
213 m_bDateTimeField = false;
214 try
215 {
216 sal_Int32 nFieldType = 0;
217 xField->getPropertyValue(PROPERTY_FIELDTYPE) >>= nFieldType;
218 m_bDateTimeField = (nFieldType == DataType::TIMESTAMP);
219 }
220 catch(const Exception&)
221 {
222 }
223}
224
225
227{
228 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
229 if ( aControlValue == m_aSaveValue )
230 return true;
231
232 if ( !aControlValue.hasValue() )
233 m_xColumnUpdate->updateNull();
234 else
235 {
236 try
237 {
238 util::Time aTime;
239 if ( !( aControlValue >>= aTime ) )
240 {
241 sal_Int64 nAsInt(0);
242 aControlValue >>= nAsInt;
243 aTime = DBTypeConversion::toTime(nAsInt);
244 }
245
246 if (!m_bDateTimeField)
247 m_xColumnUpdate->updateTime(aTime);
248 else
249 {
250 util::DateTime aDateTime = m_xColumn->getTimestamp();
251 if (aDateTime.Year == 0 && aDateTime.Month == 0 && aDateTime.Day == 0)
252 aDateTime = ::com::sun::star::util::DateTime(0,0,0,0,30,12,1899, false);
253 aDateTime.NanoSeconds = aTime.NanoSeconds;
254 aDateTime.Seconds = aTime.Seconds;
255 aDateTime.Minutes = aTime.Minutes;
256 aDateTime.Hours = aTime.Hours;
257 m_xColumnUpdate->updateTimestamp(aDateTime);
258 }
259 }
260 catch(const Exception&)
261 {
262 return false;
263 }
264 }
265 m_aSaveValue = aControlValue;
266 return true;
267}
268
269
271{
272 return getControlValue();
273}
274
275
276Any OTimeModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
277{
278 return _rExternalValue;
279}
280
281
283{
284 return getControlValue();
285}
286
287
289{
290 util::Time aTime = m_xColumn->getTime();
291 if ( m_xColumn->wasNull() )
292 m_aSaveValue.clear();
293 else
294 m_aSaveValue <<= aTime;
295
296 return m_aSaveValue;
297}
298
299
301{
302 return m_aDefault;
303}
304
305
307{
309 m_aSaveValue.clear();
310}
311
312
314{
315 return Sequence< Type >( & cppu::UnoType<util::Time>::get(), 1 );
316}
317
318} // namespace frm
319
320extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
321com_sun_star_form_OTimeModel_get_implementation(css::uno::XComponentContext* component,
322 css::uno::Sequence<css::uno::Any> const &)
323{
324 return cppu::acquire(new frm::OTimeModel(component));
325}
326
327extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
328com_sun_star_form_OTimeControl_get_implementation(css::uno::XComponentContext* component,
329 css::uno::Sequence<css::uno::Any> const &)
330{
331 return cppu::acquire(new frm::OTimeControl(component));
332}
333
334/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OTimeModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Time.cxx:321
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OTimeControl_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Time.cxx:328
sal_Int32 getValuePropertyAggHandle() const
virtual void onConnectedDbColumn(const css::uno::Reference< css::uno::XInterface > &_rxForm)
called whenever a connection to a database column has been established
void initValueProperty(const OUString &_rValuePropertyName, sal_Int32 _nValuePropertyExternalHandle)
initializes the part of the class which is related to the control value.
css::uno::Reference< css::sdb::XColumn > m_xColumn
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
virtual void resetNoBroadcast()
called to reset the control to some kind of default.
const css::uno::Reference< css::beans::XPropertySet > & getField() const
css::uno::Reference< css::sdb::XColumnUpdate > m_xColumnUpdate
virtual css::uno::Any getControlValue() const
retrieves the current value of the control
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: EditBase.cxx:291
css::uno::Any m_aDefault
Definition: EditBase.hxx:44
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
Definition: EditBase.cxx:268
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: EditBase.cxx:325
maintains translation tables format key <-> enum value
const css::uno::Reference< css::util::XNumberFormatsSupplier > & getFormatsSupplier() const
void setAggregateSet(const css::uno::Reference< css::beans::XFastPropertySet > &_rxAggregate, sal_Int32 _nOriginalPropertyHandle)
void getFormatKeyPropertyValue(css::uno::Any &_rValue) const
void setFormatKeyPropertyValue(const css::uno::Any &_rNewValue)
bool convertFormatKeyPropertyValue(css::uno::Any &_rConvertedValue, css::uno::Any &_rOldValue, const css::uno::Any &_rNewValue)
OTimeControl(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: Time.cxx:186
virtual OUString SAL_CALL getServiceName() override
Definition: Time.cxx:147
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: Time.cxx:196
virtual ~OTimeModel() override
Definition: Time.cxx:132
bool m_bDateTimeField
Definition: Time.hxx:35
virtual css::uno::Sequence< css::uno::Type > getSupportedBindingTypes() override
returns the data types which the control could use to exchange data with an external value binding
Definition: Time.cxx:313
virtual css::uno::Any translateControlValueToExternalValue() const override
commits the current control value to our external value binding
Definition: Time.cxx:270
virtual css::uno::Any translateDbColumnToControlValue() override
translates a db column value into a control value.
Definition: Time.cxx:288
css::uno::Any m_aSaveValue
Definition: Time.hxx:34
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
Definition: Time.cxx:169
OTimeModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
virtual void onConnectedDbColumn(const css::uno::Reference< css::uno::XInterface > &_rxForm) override
called whenever a connection to a database column has been established
Definition: Time.cxx:206
virtual css::uno::Any getDefaultForReset() const override
returns the default which should be used when resetting the control
Definition: Time.cxx:300
virtual css::uno::Any translateExternalValueToControlValue(const css::uno::Any &_rExternalValue) const override
translates the given value, which was obtained from the current external value binding,...
Definition: Time.cxx:276
virtual css::uno::Any translateControlValueToValidatableValue() const override
retrieves the current value of the control, in a shape which can be used with our external validator.
Definition: Time.cxx:282
virtual bool commitControlValueToDbColumn(bool _bPostReset) override
commits the current control value to the database column we're bound to @precond we're properly bound...
Definition: Time.cxx:226
virtual void resetNoBroadcast() override
called to reset the control to some kind of default.
Definition: Time.cxx:306
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
Definition: Time.cxx:154
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: Time.cxx:139
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_DEFAULT_TIME
Definition: frm_strings.hxx:87
constexpr OUStringLiteral PROPERTY_TIME
Definition: frm_strings.hxx:57
constexpr OUStringLiteral PROPERTY_FIELDTYPE
Definition: frm_strings.hxx:90
constexpr OUStringLiteral PROPERTY_FORMATKEY
Definition: frm_strings.hxx:66
constexpr OUStringLiteral PROPERTY_FORMATSSUPPLIER
Definition: frm_strings.hxx:67
@ Exception
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
#define PROPERTY_ID_FORMATKEY
Definition: property.hxx:68
#define PROPERTY_ID_TIMEFORMAT
Definition: property.hxx:137
#define PROPERTY_ID_DEFAULT_TIME
Definition: property.hxx:175
#define PROPERTY_ID_FORMATSSUPPLIER
Definition: property.hxx:190
#define PROPERTY_ID_TIME
Definition: property.hxx:134
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
constexpr OUStringLiteral FRM_SUN_CONTROL_TIMEFIELD
Definition: services.hxx:159
constexpr OUStringLiteral FRM_SUN_COMPONENT_TIMEFIELD
Definition: services.hxx:124
constexpr OUStringLiteral VALIDATABLE_BINDABLE_CONTROL_MODEL
Definition: services.hxx:184
constexpr OUStringLiteral VCL_CONTROL_TIMEFIELD
Definition: services.hxx:31
constexpr OUStringLiteral FRM_COMPONENT_TIMEFIELD
Definition: services.hxx:78
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_TIMEFIELD
Definition: services.hxx:99
constexpr OUStringLiteral BINDABLE_DATA_AWARE_CONTROL_MODEL
Definition: services.hxx:181
constexpr OUStringLiteral FRM_SUN_COMPONENT_DATABASE_TIMEFIELD
Definition: services.hxx:145
constexpr OUStringLiteral VCL_CONTROLMODEL_TIMEFIELD
Definition: services.hxx:49
constexpr OUStringLiteral DATA_AWARE_CONTROL_MODEL
Definition: services.hxx:182
constexpr OUStringLiteral VALIDATABLE_CONTROL_MODEL
Definition: services.hxx:183
constexpr OUStringLiteral BINDABLE_DATABASE_TIME_FIELD
Definition: services.hxx:177
constexpr OUStringLiteral BINDABLE_CONTROL_MODEL
Definition: services.hxx:179
unsigned char sal_Bool