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 .
20 #include "Pattern.hxx"
21 #include <property.hxx>
22 #include <services.hxx>
23 #include <tools/debug.hxx>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/form/FormComponentType.hpp>
27 using ::com::sun::star::uno::Reference
;
28 using ::com::sun::star::uno::Sequence
;
29 using ::com::sun::star::uno::XComponentContext
;
30 using ::com::sun::star::beans::Property
;
31 using ::com::sun::star::uno::XInterface
;
32 using ::com::sun::star::uno::Any
;
33 using ::com::sun::star::sdbc::XRowSet
;
34 using ::com::sun::star::uno::UNO_QUERY
;
36 namespace FormComponentType
= ::com::sun::star::form::FormComponentType
;
41 OPatternControl::OPatternControl(const Reference
<XComponentContext
>& _rxFactory
)
42 :OBoundControl(_rxFactory
, VCL_CONTROL_PATTERNFIELD
)
46 css::uno::Sequence
<OUString
> OPatternControl::getSupportedServiceNames()
48 css::uno::Sequence
<OUString
> aSupported
= OBoundControl::getSupportedServiceNames();
49 aSupported
.realloc(aSupported
.getLength() + 2);
51 OUString
*pArray
= aSupported
.getArray();
52 pArray
[aSupported
.getLength()-2] = FRM_SUN_CONTROL_PATTERNFIELD
;
53 pArray
[aSupported
.getLength()-1] = STARDIV_ONE_FORM_CONTROL_PATTERNFIELD
;
61 OPatternModel::OPatternModel(const Reference
<XComponentContext
>& _rxFactory
)
62 :OEditBaseModel( _rxFactory
, VCL_CONTROLMODEL_PATTERNFIELD
, FRM_SUN_CONTROL_PATTERNFIELD
, false, false )
63 // use the old control name for compatibility reasons
66 m_nClassId
= FormComponentType::PATTERNFIELD
;
67 initValueProperty( PROPERTY_TEXT
, PROPERTY_ID_TEXT
);
71 OPatternModel::OPatternModel( const OPatternModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
72 :OEditBaseModel( _pOriginal
, _rxFactory
)
77 OPatternModel::~OPatternModel()
83 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
OPatternModel::createClone()
85 rtl::Reference
<OPatternModel
> pClone
= new OPatternModel(this, getContext());
86 pClone
->clonedFrom(this);
92 css::uno::Sequence
<OUString
> SAL_CALL
OPatternModel::getSupportedServiceNames()
94 css::uno::Sequence
<OUString
> aSupported
= OBoundControlModel::getSupportedServiceNames();
95 aSupported
.realloc(aSupported
.getLength() + 3);
97 OUString
*pArray
= aSupported
.getArray();
98 pArray
[aSupported
.getLength()-3] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD
;
99 pArray
[aSupported
.getLength()-2] = FRM_SUN_COMPONENT_PATTERNFIELD
;
100 pArray
[aSupported
.getLength()-1] = FRM_COMPONENT_PATTERNFIELD
;
105 void OPatternModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
107 OEditBaseModel::describeFixedProperties( _rProps
);
108 sal_Int32 nOldCount
= _rProps
.getLength();
109 _rProps
.realloc( nOldCount
+ 4);
110 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
111 *pProperties
++ = css::beans::Property(PROPERTY_DEFAULT_TEXT
, PROPERTY_ID_DEFAULT_TEXT
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
);
112 *pProperties
++ = css::beans::Property(PROPERTY_EMPTY_IS_NULL
, PROPERTY_ID_EMPTY_IS_NULL
, cppu::UnoType
<bool>::get(),
113 css::beans::PropertyAttribute::BOUND
);
114 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
115 *pProperties
++ = css::beans::Property(PROPERTY_FILTERPROPOSAL
, PROPERTY_ID_FILTERPROPOSAL
, cppu::UnoType
<sal_Bool
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
);
116 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
120 OUString SAL_CALL
OPatternModel::getServiceName()
122 return FRM_COMPONENT_PATTERNFIELD
; // old (non-sun) name for compatibility !
126 bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
128 Any
aNewValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
130 if ( aNewValue
== m_aLastKnownValue
)
134 aNewValue
>>= sNewValue
;
136 if ( !aNewValue
.hasValue()
137 || ( sNewValue
.isEmpty() // an empty string
138 && m_bEmptyIsNull
// which should be interpreted as NULL
142 m_xColumnUpdate
->updateNull();
146 OSL_ENSURE(m_pFormattedValue
,
147 "OPatternModel::commitControlValueToDbColumn: no value helper!");
148 if (!m_pFormattedValue
)
151 if ( !m_pFormattedValue
->setFormattedValue( sNewValue
) )
155 m_aLastKnownValue
= std::move(aNewValue
);
161 void OPatternModel::onConnectedDbColumn( const Reference
< XInterface
>& _rxForm
)
163 OEditBaseModel::onConnectedDbColumn( _rxForm
);
165 Reference
< XPropertySet
> xField( getField() );
169 m_pFormattedValue
.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference
< XRowSet
>( _rxForm
, UNO_QUERY
), xField
) );
173 void OPatternModel::onDisconnectedDbColumn()
175 OEditBaseModel::onDisconnectedDbColumn();
176 m_pFormattedValue
.reset();
179 // XPropertyChangeListener
181 Any
OPatternModel::translateDbColumnToControlValue()
183 OSL_PRECOND(m_pFormattedValue
,
184 "OPatternModel::translateDbColumnToControlValue: no value helper!");
186 if (m_pFormattedValue
)
188 OUString
sValue( m_pFormattedValue
->getFormattedValue() );
189 if ( sValue
.isEmpty()
190 && m_pFormattedValue
->getColumn().is()
191 && m_pFormattedValue
->getColumn()->wasNull()
194 m_aLastKnownValue
.clear();
198 m_aLastKnownValue
<<= sValue
;
202 m_aLastKnownValue
.clear();
204 return m_aLastKnownValue
.hasValue() ? m_aLastKnownValue
: Any( OUString() );
205 // (m_aLastKnownValue is allowed to be VOID, the control value isn't)
210 Any
OPatternModel::getDefaultForReset() const
212 return Any( m_aDefaultText
);
215 void OPatternModel::resetNoBroadcast()
217 OEditBaseModel::resetNoBroadcast();
218 m_aLastKnownValue
.clear();
223 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
224 com_sun_star_form_OPatternModel_get_implementation(css::uno::XComponentContext
* component
,
225 css::uno::Sequence
<css::uno::Any
> const &)
227 return cppu::acquire(new frm::OPatternModel(component
));
230 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
231 com_sun_star_form_OPatternControl_get_implementation(css::uno::XComponentContext
* component
,
232 css::uno::Sequence
<css::uno::Any
> const &)
234 return cppu::acquire(new frm::OPatternControl(component
));
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */