LibreOffice Module forms (master) 1
ListBox.hxx
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#pragma once
21
22#include <FormComponent.hxx>
23#include "cachedrowset.hxx"
24#include "errorbroadcaster.hxx"
25#include "entrylisthelper.hxx"
26
27#include <com/sun/star/form/ListSourceType.hpp>
28#include <com/sun/star/awt/XItemListener.hpp>
29#include <com/sun/star/awt/XFocusListener.hpp>
30#include <com/sun/star/awt/XListBox.hpp>
31#include <com/sun/star/form/XChangeBroadcaster.hpp>
32
37#include <vcl/timer.hxx>
38#include <vcl/idle.hxx>
39
40#include <vector>
41
42using namespace comphelper;
43
93namespace frm
94{
95
96typedef ::std::vector< ::connectivity::ORowSetValue > ValueList;
97
99 ,public OEntryListHelper
100 ,public OErrorBroadcaster
101{
102
103 CachedRowSet m_aListRowSet; // the row set to fill the list
105
106 // <properties>
107 css::form::ListSourceType m_eListSourceType; // type of list source
108 css::uno::Any m_aBoundColumn;
110 ValueList m_aBoundValues; // do not write directly; use setBoundValues()
113 css::uno::Sequence<sal_Int16> m_aDefaultSelectSeq; // DefaultSelected
114 // </properties>
115
116 mutable sal_Int16 m_nNULLPos; // position of the NULL value in our list
118
119private:
121
122 virtual css::uno::Sequence< css::uno::Type> _getTypes() override;
123
124public:
126 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory
127 );
129 const OListBoxModel* _pOriginal,
130 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory
131 );
132 virtual ~OListBoxModel() override;
133
134// XServiceInfo
135 OUString SAL_CALL getImplementationName() override
136 { return "com.sun.star.form.OListBoxModel"; }
137
138 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
139
140// UNO binding
142 virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& _rType ) override;
143
144// OComponentHelper
145 virtual void SAL_CALL disposing() override;
146
147// OPropertySetHelper
148 virtual void SAL_CALL getFastPropertyValue(css::uno::Any& rValue, sal_Int32 nHandle) const override;
149 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override;
150 virtual sal_Bool SAL_CALL convertFastPropertyValue(
151 css::uno::Any& _rConvertedValue, css::uno::Any& _rOldValue, sal_Int32 _nHandle, const css::uno::Any& _rValue ) override;
152
153private:
154 static const ::connectivity::ORowSetValue s_aEmptyValue;
155 static const ::connectivity::ORowSetValue s_aEmptyStringValue;
156
157 // XMultiPropertySet
158 virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString >& PropertyNames, const css::uno::Sequence< css::uno::Any >& Values) override;
159
160 // XPersistObject
161 virtual OUString SAL_CALL getServiceName() override;
162 virtual void SAL_CALL
163 write(const css::uno::Reference< css::io::XObjectOutputStream>& _rxOutStream) override;
164 virtual void SAL_CALL
165 read(const css::uno::Reference< css::io::XObjectInputStream>& _rxInStream) override;
166
167 // OControlModel's property handling
168 virtual void describeFixedProperties(
169 css::uno::Sequence< css::beans::Property >& /* [out] */ _rProps
170 ) const override;
171 virtual void describeAggregateProperties(
172 css::uno::Sequence< css::beans::Property >& /* [out] */ _rAggregateProps
173 ) const override;
174
175 // XEventListener
176 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
177
178 // OPropertyChangeListener
179 virtual void _propertyChanged( const css::beans::PropertyChangeEvent& _rEvt ) override;
180
181 // prevent method hiding
184
185 // OBoundControlModel overridables
186 virtual css::uno::Any translateDbColumnToControlValue( ) override;
187 virtual css::uno::Sequence< css::uno::Type >
188 getSupportedBindingTypes() override;
189 virtual css::uno::Any translateExternalValueToControlValue( const css::uno::Any& _rExternalValue ) const override;
190 virtual css::uno::Any translateControlValueToExternalValue( ) const override;
191 virtual css::uno::Any translateControlValueToValidatableValue( ) const override;
192 virtual bool commitControlValueToDbColumn( bool _bPostReset ) override;
193
194 virtual void onConnectedDbColumn( const css::uno::Reference< css::uno::XInterface >& _rxForm ) override;
195 virtual void onDisconnectedDbColumn() override;
196
197 virtual css::uno::Any getDefaultForReset() const override;
198 virtual void resetNoBroadcast() override;
199
200 virtual css::uno::Any getCurrentFormComponentValue() const override;
201
202 // OEntryListHelper overridables
203 virtual void stringItemListChanged( ControlModelLock& _rInstanceLock ) override;
204 virtual void refreshInternalEntryList() override;
205
206 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
207
208 void init();
209 css::uno::Any getCurrentSingleValue() const;
210 css::uno::Sequence<css::uno::Any> getCurrentMultiValue() const;
211 css::uno::Sequence< sal_Int16 > translateBindingValuesToControlValue(
212 const css::uno::Sequence< const css::uno::Any > &i_aValues)
213 const;
214 css::uno::Sequence< sal_Int16 > translateDbValueToControlValue(
215 const ::connectivity::ORowSetValue &aValue)
216 const;
217
218 void loadData( bool _bForce );
219
223 void impl_refreshDbEntryList( bool _bForce );
224
225 void setBoundValues(ValueList &&);
226 void clearBoundValues();
227
229
230 sal_Int32 getValueType() const;
231
232 void convertBoundValues(sal_Int32 nType) const;
233};
234
235
236//= OListBoxControl
237
238typedef ::cppu::ImplHelper4 < css::awt::XFocusListener
239 , css::awt::XItemListener
240 , css::awt::XListBox
241 , css::form::XChangeBroadcaster
243
246 ,public IEventProcessor
247{
248private:
251
252 css::uno::Any m_aCurrentSelection;
254
255 css::uno::Reference< css::awt::XListBox >
257
260
261protected:
262 // UNO binding
263 virtual css::uno::Sequence< css::uno::Type> _getTypes() override;
264
265public:
266 explicit OListBoxControl(const css::uno::Reference< css::uno::XComponentContext>& _rxFactory);
267 virtual ~OListBoxControl() override;
268
269 // UNO binding
271 virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& _rType ) override;
272
273// XServiceInfo
274 OUString SAL_CALL getImplementationName() override
275 { return "com.sun.star.form.OListBoxControl"; }
276
277 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
278
279// XChangeBroadcaster
280 virtual void SAL_CALL addChangeListener(const css::uno::Reference< css::form::XChangeListener>& _rxListener) override;
281 virtual void SAL_CALL removeChangeListener(const css::uno::Reference< css::form::XChangeListener>& _rxListener) override;
282
283// XFocusListener
284 virtual void SAL_CALL focusGained(const css::awt::FocusEvent& _rEvent) override;
285 virtual void SAL_CALL focusLost(const css::awt::FocusEvent& _rEvent) override;
286
287// XItemListener
288 virtual void SAL_CALL itemStateChanged(const css::awt::ItemEvent& _rEvent) override;
289
290// XEventListener
291 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
292
293// OComponentHelper
294 virtual void SAL_CALL disposing() override;
295
296// XListBox
297 virtual void SAL_CALL addItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
298 virtual void SAL_CALL removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
299 virtual void SAL_CALL addActionListener( const css::uno::Reference< css::awt::XActionListener >& l ) override;
300 virtual void SAL_CALL removeActionListener( const css::uno::Reference< css::awt::XActionListener >& l ) override;
301 virtual void SAL_CALL addItem( const OUString& aItem, ::sal_Int16 nPos ) override;
302 virtual void SAL_CALL addItems( const css::uno::Sequence< OUString >& aItems, ::sal_Int16 nPos ) override;
303 virtual void SAL_CALL removeItems( ::sal_Int16 nPos, ::sal_Int16 nCount ) override;
304 virtual ::sal_Int16 SAL_CALL getItemCount( ) override;
305 virtual OUString SAL_CALL getItem( ::sal_Int16 nPos ) override;
306 virtual css::uno::Sequence< OUString > SAL_CALL getItems( ) override;
307 virtual ::sal_Int16 SAL_CALL getSelectedItemPos( ) override;
308 virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getSelectedItemsPos( ) override;
309 virtual OUString SAL_CALL getSelectedItem( ) override;
310 virtual css::uno::Sequence< OUString > SAL_CALL getSelectedItems( ) override;
311 virtual void SAL_CALL selectItemPos( ::sal_Int16 nPos, sal_Bool bSelect ) override;
312 virtual void SAL_CALL selectItemsPos( const css::uno::Sequence< ::sal_Int16 >& aPositions, sal_Bool bSelect ) override;
313 virtual void SAL_CALL selectItem( const OUString& aItem, sal_Bool bSelect ) override;
314 virtual sal_Bool SAL_CALL isMutipleMode( ) override;
315 virtual void SAL_CALL setMultipleMode( sal_Bool bMulti ) override;
316 virtual ::sal_Int16 SAL_CALL getDropDownLineCount( ) override;
317 virtual void SAL_CALL setDropDownLineCount( ::sal_Int16 nLines ) override;
318 virtual void SAL_CALL makeVisible( ::sal_Int16 nEntry ) override;
319
320protected:
321 // IEventProcessor
322 virtual void processEvent( const ::comphelper::AnyEvent& _rEvent ) override;
323
324private:
325 DECL_LINK( OnTimeout, Timer*, void );
326};
327
328
329}
330
331
332/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
caches a result set obtained from a SQL statement
class whose instances lock an OControlModel
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &aProps) override
virtual OUString SAL_CALL getSelectedItem() override
Definition: ListBox.cxx:2113
virtual void SAL_CALL setMultipleMode(sal_Bool bMulti) override
Definition: ListBox.cxx:2158
virtual void SAL_CALL addItems(const css::uno::Sequence< OUString > &aItems, ::sal_Int16 nPos) override
Definition: ListBox.cxx:2059
OUString SAL_CALL getImplementationName() override
Definition: ListBox.hxx:274
virtual void SAL_CALL disposing() override
Definition: ListBox.cxx:1979
virtual void SAL_CALL focusLost(const css::awt::FocusEvent &_rEvent) override
Definition: ListBox.cxx:1882
virtual css::uno::Sequence< OUString > SAL_CALL getItems() override
Definition: ListBox.cxx:2089
virtual void SAL_CALL addActionListener(const css::uno::Reference< css::awt::XActionListener > &l) override
Definition: ListBox.cxx:2038
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::Reference< css::awt::XListBox > m_xAggregateListBox
Definition: ListBox.hxx:256
virtual void SAL_CALL focusGained(const css::awt::FocusEvent &_rEvent) override
Definition: ListBox.cxx:1867
virtual void SAL_CALL makeVisible(::sal_Int16 nEntry) override
Definition: ListBox.cxx:2180
virtual ~OListBoxControl() override
Definition: ListBox.cxx:1839
virtual void SAL_CALL selectItemPos(::sal_Int16 nPos, sal_Bool bSelect) override
Definition: ListBox.cxx:2129
virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getSelectedItemsPos() override
Definition: ListBox.cxx:2105
virtual void SAL_CALL itemStateChanged(const css::awt::ItemEvent &_rEvent) override
Definition: ListBox.cxx:1889
::comphelper::OInterfaceContainerHelper3< css::form::XChangeListener > m_aChangeListeners
Definition: ListBox.hxx:249
virtual void SAL_CALL removeItems(::sal_Int16 nPos, ::sal_Int16 nCount) override
Definition: ListBox.cxx:2066
virtual ::sal_Int16 SAL_CALL getDropDownLineCount() override
Definition: ListBox.cxx:2165
virtual void SAL_CALL setDropDownLineCount(::sal_Int16 nLines) override
Definition: ListBox.cxx:2173
::rtl::Reference< ::comphelper::AsyncEventNotifier > m_pItemBroadcaster
Definition: ListBox.hxx:259
virtual void SAL_CALL addChangeListener(const css::uno::Reference< css::form::XChangeListener > &_rxListener) override
Definition: ListBox.cxx:1966
DECL_LINK(OnTimeout, Timer *, void)
virtual OUString SAL_CALL getItem(::sal_Int16 nPos) override
Definition: ListBox.cxx:2081
OListBoxControl(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
Definition: ListBox.cxx:1811
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: ListBox.cxx:1853
virtual void processEvent(const ::comphelper::AnyEvent &_rEvent) override
Definition: ListBox.cxx:2007
virtual sal_Bool SAL_CALL isMutipleMode() override
Definition: ListBox.cxx:2150
virtual void SAL_CALL selectItem(const OUString &aItem, sal_Bool bSelect) override
Definition: ListBox.cxx:2143
virtual void SAL_CALL addItemListener(const css::uno::Reference< css::awt::XItemListener > &l) override
Definition: ListBox.cxx:2026
css::uno::Any m_aCurrentSelection
Definition: ListBox.hxx:252
virtual ::sal_Int16 SAL_CALL getItemCount() override
Definition: ListBox.cxx:2073
virtual void SAL_CALL selectItemsPos(const css::uno::Sequence< ::sal_Int16 > &aPositions, sal_Bool bSelect) override
Definition: ListBox.cxx:2136
virtual void SAL_CALL removeActionListener(const css::uno::Reference< css::awt::XActionListener > &l) override
Definition: ListBox.cxx:2045
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
Definition: ListBox.cxx:1789
virtual void SAL_CALL addItem(const OUString &aItem, ::sal_Int16 nPos) override
Definition: ListBox.cxx:2052
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
Definition: ListBox.cxx:1798
virtual css::uno::Sequence< OUString > SAL_CALL getSelectedItems() override
Definition: ListBox.cxx:2121
virtual ::sal_Int16 SAL_CALL getSelectedItemPos() override
Definition: ListBox.cxx:2097
virtual void SAL_CALL removeItemListener(const css::uno::Reference< css::awt::XItemListener > &l) override
Definition: ListBox.cxx:2032
virtual void SAL_CALL removeChangeListener(const css::uno::Reference< css::form::XChangeListener > &_rxListener) override
Definition: ListBox.cxx:1972
::comphelper::OInterfaceContainerHelper3< css::awt::XItemListener > m_aItemListeners
Definition: ListBox.hxx:250
virtual void resetNoBroadcast() override
called to reset the control to some kind of default.
Definition: ListBox.cxx:1297
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: ListBox.cxx:1160
virtual css::uno::Any translateControlValueToExternalValue() const override
commits the current control value to our external value binding
Definition: ListBox.cxx:1579
ValueList m_aListSourceValues
Definition: ListBox.hxx:109
virtual ~OListBoxModel() override
Definition: ListBox.cxx:185
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &_rEvt) override
Definition: ListBox.cxx:518
CachedRowSet m_aListRowSet
Definition: ListBox.hxx:103
static const ::connectivity::ORowSetValue s_aEmptyStringValue
Definition: ListBox.hxx:155
virtual void onDisconnectedDbColumn() override
called whenever a connection to a database column has been suspended
Definition: ListBox.cxx:1037
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
Definition: ListBox.cxx:251
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &_rConvertedValue, css::uno::Any &_rOldValue, sal_Int32 _nHandle, const css::uno::Any &_rValue) override
Definition: ListBox.cxx:402
ValueList impl_getValues() const
Definition: ListBox.cxx:1103
css::form::ListSourceType m_eListSourceType
Definition: ListBox.hxx:107
void setBoundValues(ValueList &&)
Definition: ListBox.cxx:1053
::connectivity::ORowSetValue m_aSaveValue
Definition: ListBox.hxx:104
virtual void onConnectedDbColumn(const css::uno::Reference< css::uno::XInterface > &_rxForm) override
called whenever a connection to a database column has been established
Definition: ListBox.cxx:1023
sal_Int32 m_nConvertedBoundValuesType
Definition: ListBox.hxx:112
virtual OUString SAL_CALL getServiceName() override
Definition: ListBox.cxx:554
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: ListBox.cxx:197
OListBoxModel(const OListBoxModel *_pOriginal, const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
css::uno::Any getCurrentSingleValue() const
Definition: ListBox.cxx:1650
::connectivity::ORowSetValue getFirstSelectedValue() const
Definition: ListBox.cxx:1131
ValueList m_aBoundValues
Definition: ListBox.hxx:110
virtual css::uno::Any getCurrentFormComponentValue() const override
retrieves the current value of the form component
Definition: ListBox.cxx:1686
OUString SAL_CALL getImplementationName() override
Definition: ListBox.hxx:135
css::uno::Sequence< css::uno::Any > getCurrentMultiValue() const
Definition: ListBox.cxx:1668
void clearBoundValues()
Definition: ListBox.cxx:1060
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: ListBox.cxx:1360
virtual void SAL_CALL disposing() override
Definition: ListBox.cxx:243
ValueList m_aConvertedBoundValues
Definition: ListBox.hxx:111
virtual void refreshInternalEntryList() override
called when XRefreshable::refresh has been called, and we do not have an external list source
Definition: ListBox.cxx:1779
static const ::connectivity::ORowSetValue s_aEmptyValue
Definition: ListBox.hxx:154
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: ListBox.cxx:297
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: ListBox.cxx:1716
virtual css::uno::Any translateDbColumnToControlValue() override
translates a db column value into a control value.
Definition: ListBox.cxx:1254
virtual css::uno::Any getDefaultForReset() const override
returns the default which should be used when resetting the control
Definition: ListBox.cxx:1277
css::uno::Any m_aBoundColumn
Definition: ListBox.hxx:108
sal_Int32 getValueType() const
Definition: ListBox.cxx:1096
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
sal_Int16 m_nNULLPos
Definition: ListBox.hxx:116
css::uno::Sequence< sal_Int16 > m_aDefaultSelectSeq
Definition: ListBox.hxx:113
void impl_refreshDbEntryList(bool _bForce)
refreshes the list boxes list data @precond we don't actually have an external list source
Definition: ListBox.cxx:1765
sal_Int32 m_nBoundColumnType
Definition: ListBox.hxx:117
void convertBoundValues(sal_Int32 nType) const
Definition: ListBox.cxx:1067
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: ListBox.cxx:498
virtual void stringItemListChanged(ControlModelLock &_rInstanceLock) override
announces that the list of entries has changed.
Definition: ListBox.cxx:1730
void loadData(bool _bForce)
Definition: ListBox.cxx:711
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Sequence< css::uno::Any > &Values) override
Definition: ListBox.cxx:461
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: ListBox.cxx:1643
virtual void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream) override
Definition: ListBox.cxx:596
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
Definition: ListBox.cxx:231
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
Definition: ListBox.cxx:131
virtual void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream) override
Definition: ListBox.cxx:560
OListBoxModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
css::uno::Sequence< sal_Int16 > translateBindingValuesToControlValue(const css::uno::Sequence< const css::uno::Any > &i_aValues) const
Definition: ListBox.cxx:1213
css::uno::Sequence< sal_Int16 > translateDbValueToControlValue(const ::connectivity::ORowSetValue &aValue) const
Definition: ListBox.cxx:1185
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: ListBox.cxx:206
virtual void describeAggregateProperties(css::uno::Sequence< css::beans::Property > &_rAggregateProps) const override
describes the properties of our aggregate
Definition: ListBox.cxx:544
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
::std::vector< ::connectivity::ORowSetValue > ValueList
Definition: ListBox.hxx:96
::cppu::ImplHelper4< css::awt::XFocusListener, css::awt::XItemListener, css::awt::XListBox, css::form::XChangeBroadcaster > OListBoxControl_BASE
Definition: ListBox.hxx:242
unsigned char sal_Bool
#define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass)