LibreOffice Module forms (master) 1
Pattern.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 "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>
26
27using ::com::sun::star::uno::Reference;
28using ::com::sun::star::uno::Sequence;
29using ::com::sun::star::uno::XComponentContext;
30using ::com::sun::star::beans::Property;
31using ::com::sun::star::uno::XInterface;
32using ::com::sun::star::uno::Any;
33using ::com::sun::star::sdbc::XRowSet;
34using ::com::sun::star::uno::UNO_QUERY;
35
36namespace FormComponentType = ::com::sun::star::form::FormComponentType;
37
38namespace frm
39{
40
41OPatternControl::OPatternControl(const Reference<XComponentContext>& _rxFactory)
43{
44}
45
46css::uno::Sequence<OUString> OPatternControl::getSupportedServiceNames()
47{
48 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
49 aSupported.realloc(aSupported.getLength() + 2);
50
51 OUString*pArray = aSupported.getArray();
52 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_PATTERNFIELD;
53 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_PATTERNFIELD;
54 return aSupported;
55}
56
57
58// OPatternModel
59
60
61OPatternModel::OPatternModel(const Reference<XComponentContext>& _rxFactory)
63 // use the old control name for compytibility reasons
64{
65
66 m_nClassId = FormComponentType::PATTERNFIELD;
67 initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
68}
69
70
71OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
72 :OEditBaseModel( _pOriginal, _rxFactory )
73{
74}
75
76
78{
79}
80
81// XCloneable
82
83css::uno::Reference< css::util::XCloneable > SAL_CALL OPatternModel::createClone()
84{
86 pClone->clonedFrom(this);
87 return pClone;
88}
89
90// XServiceInfo
91
92css::uno::Sequence<OUString> SAL_CALL OPatternModel::getSupportedServiceNames()
93{
94 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
95 aSupported.realloc(aSupported.getLength() + 3);
96
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;
101 return aSupported;
102}
103
104
105void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
106{
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 ?");
117}
118
119
121{
122 return FRM_COMPONENT_PATTERNFIELD; // old (non-sun) name for compatibility !
123}
124
125
127{
128 Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
129
130 if ( aNewValue == m_aLastKnownValue )
131 return true;
132
133 OUString sNewValue;
134 aNewValue >>= sNewValue;
135
136 if ( !aNewValue.hasValue()
137 || ( sNewValue.isEmpty() // an empty string
138 && m_bEmptyIsNull // which should be interpreted as NULL
139 )
140 )
141 {
142 m_xColumnUpdate->updateNull();
143 }
144 else
145 {
146 OSL_ENSURE(m_pFormattedValue,
147 "OPatternModel::commitControlValueToDbColumn: no value helper!");
149 return false;
150
151 if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
152 return false;
153 }
154
155 m_aLastKnownValue = aNewValue;
156
157 return true;
158}
159
160
161void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
162{
164
165 Reference< XPropertySet > xField( getField() );
166 if ( !xField.is() )
167 return;
168
169 m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
170}
171
172
174{
176 m_pFormattedValue.reset();
177}
178
179// XPropertyChangeListener
180
182{
183 OSL_PRECOND(m_pFormattedValue,
184 "OPatternModel::translateDbColumnToControlValue: no value helper!");
185
187 {
188 OUString sValue( m_pFormattedValue->getFormattedValue() );
189 if ( sValue.isEmpty()
190 && m_pFormattedValue->getColumn().is()
191 && m_pFormattedValue->getColumn()->wasNull()
192 )
193 {
194 m_aLastKnownValue.clear();
195 }
196 else
197 {
198 m_aLastKnownValue <<= sValue;
199 }
200 }
201 else
202 m_aLastKnownValue.clear();
203
204 return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : Any( OUString() );
205 // (m_aLastKnownValue is allowed to be VOID, the control value isn't)
206}
207
208// XReset
209
211{
212 return Any( m_aDefaultText );
213}
214
216{
218 m_aLastKnownValue.clear();
219}
220
221} // namespace frm
222
223extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
224com_sun_star_form_OPatternModel_get_implementation(css::uno::XComponentContext* component,
225 css::uno::Sequence<css::uno::Any> const &)
226{
227 return cppu::acquire(new frm::OPatternModel(component));
228}
229
230extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
231com_sun_star_form_OPatternControl_get_implementation(css::uno::XComponentContext* component,
232 css::uno::Sequence<css::uno::Any> const &)
233{
234 return cppu::acquire(new frm::OPatternControl(component));
235}
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OPatternControl_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Pattern.cxx:231
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OPatternModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Pattern.cxx:224
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
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
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 void onDisconnectedDbColumn()
called whenever a connection to a database column has been suspended
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
OUString m_aDefaultText
Definition: EditBase.hxx:45
OPatternControl(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
Definition: Pattern.cxx:41
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Pattern.cxx:46
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: Pattern.cxx:126
virtual void onConnectedDbColumn(const css::uno::Reference< css::uno::XInterface > &_rxForm) override
called whenever a connection to a database column has been established
Definition: Pattern.cxx:161
virtual void resetNoBroadcast() override
called to reset the control to some kind of default.
Definition: Pattern.cxx:215
::std::unique_ptr< ::dbtools::FormattedColumnValue > m_pFormattedValue
Definition: Pattern.hxx:38
virtual css::uno::Any translateDbColumnToControlValue() override
translates a db column value into a control value.
Definition: Pattern.cxx:181
virtual void onDisconnectedDbColumn() override
called whenever a connection to a database column has been suspended
Definition: Pattern.cxx:173
virtual ~OPatternModel() override
Definition: Pattern.cxx:77
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: Pattern.cxx:83
css::uno::Any m_aLastKnownValue
Definition: Pattern.hxx:36
OPatternModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Pattern.cxx:92
virtual css::uno::Any getDefaultForReset() const override
returns the default which should be used when resetting the control
Definition: Pattern.cxx:210
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: Pattern.cxx:105
virtual OUString SAL_CALL getServiceName() override
Definition: Pattern.cxx:120
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_FILTERPROPOSAL
constexpr OUStringLiteral PROPERTY_DEFAULT_TEXT
Definition: frm_strings.hxx:64
constexpr OUStringLiteral PROPERTY_TEXT
Definition: frm_strings.hxx:33
constexpr OUStringLiteral PROPERTY_EMPTY_IS_NULL
Definition: frm_strings.hxx:75
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
#define PROPERTY_ID_FILTERPROPOSAL
Definition: property.hxx:197
#define PROPERTY_ID_EMPTY_IS_NULL
Definition: property.hxx:161
#define PROPERTY_ID_DEFAULT_TEXT
Definition: property.hxx:106
#define PROPERTY_ID_TEXT
Definition: property.hxx:83
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
constexpr OUStringLiteral FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD
Definition: services.hxx:148
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_PATTERNFIELD
Definition: services.hxx:103
constexpr OUStringLiteral FRM_SUN_COMPONENT_PATTERNFIELD
Definition: services.hxx:128
constexpr OUStringLiteral VCL_CONTROL_PATTERNFIELD
Definition: services.hxx:35
constexpr OUStringLiteral FRM_COMPONENT_PATTERNFIELD
Definition: services.hxx:82
constexpr OUStringLiteral FRM_SUN_CONTROL_PATTERNFIELD
Definition: services.hxx:163
constexpr OUStringLiteral VCL_CONTROLMODEL_PATTERNFIELD
Definition: services.hxx:53