Line data Source code
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 : #ifndef _FORMS_LISTBOX_HXX_
21 : #define _FORMS_LISTBOX_HXX_
22 :
23 : #include "FormComponent.hxx"
24 : #include "cachedrowset.hxx"
25 : #include "errorbroadcaster.hxx"
26 : #include "entrylisthelper.hxx"
27 :
28 : #include <com/sun/star/util/XNumberFormatter.hpp>
29 : #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
30 : #include <com/sun/star/form/ListSourceType.hpp>
31 : #include <com/sun/star/awt/XItemListener.hpp>
32 : #include <com/sun/star/awt/XFocusListener.hpp>
33 : #include <com/sun/star/awt/XListBox.hpp>
34 : #include <com/sun/star/form/XChangeBroadcaster.hpp>
35 : #include <com/sun/star/sdbc/DataType.hpp>
36 :
37 : #include <comphelper/asyncnotification.hxx>
38 : #include <connectivity/FValue.hxx>
39 : #include <cppuhelper/interfacecontainer.hxx>
40 : #include <cppuhelper/implbase1.hxx>
41 : #include <vcl/timer.hxx>
42 :
43 : #include <vector>
44 :
45 : //.........................................................................
46 : namespace frm
47 : {
48 :
49 : //==================================================================
50 : //= OListBoxModel
51 : //==================================================================
52 : typedef ::std::vector< ::connectivity::ORowSetValue > ValueList;
53 :
54 : class OListBoxModel :public OBoundControlModel
55 : ,public OEntryListHelper
56 : ,public OErrorBroadcaster
57 : {
58 :
59 : CachedRowSet m_aListRowSet; // the row set to fill the list
60 : ::connectivity::ORowSetValue m_aSaveValue;
61 :
62 : // <properties>
63 : ::com::sun::star::form::ListSourceType m_eListSourceType; // type der list source
64 : ::com::sun::star::uno::Any m_aBoundColumn;
65 : ValueList m_aListSourceValues;
66 : ValueList m_aBoundValues; // do not write directly; use setBoundValues()
67 : mutable ValueList m_aConvertedBoundValues;
68 : mutable sal_Int32 m_nConvertedBoundValuesType;
69 : ::com::sun::star::uno::Sequence<sal_Int16> m_aDefaultSelectSeq; // DefaultSelected
70 : // </properties>
71 :
72 : sal_Int16 m_nNULLPos; // position of the NULL value in our list
73 : sal_Int32 m_nBoundColumnType;
74 :
75 : private:
76 : ::connectivity::ORowSetValue getFirstSelectedValue() const;
77 :
78 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
79 :
80 : public:
81 : DECLARE_DEFAULT_LEAF_XTOR( OListBoxModel );
82 :
83 : // XServiceInfo
84 0 : IMPLEMENTATION_NAME(OListBoxModel);
85 : virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
86 :
87 : // UNO Anbindung
88 0 : DECLARE_UNO3_AGG_DEFAULTS(OListBoxModel, OBoundControlModel);
89 : virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
90 :
91 : // OComponentHelper
92 : virtual void SAL_CALL disposing();
93 :
94 : // OPropertySetHelper
95 : virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
96 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
97 : throw (::com::sun::star::uno::Exception);
98 : virtual sal_Bool SAL_CALL convertFastPropertyValue(
99 : ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
100 : throw (::com::sun::star::lang::IllegalArgumentException);
101 :
102 : protected:
103 : // XMultiPropertySet
104 : virtual void SAL_CALL setPropertyValues(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& PropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
105 :
106 : // XPersistObject
107 : virtual ::rtl::OUString SAL_CALL getServiceName() throw(::com::sun::star::uno::RuntimeException);
108 : virtual void SAL_CALL
109 : write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
110 : virtual void SAL_CALL
111 : read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
112 :
113 : // OControlModel's property handling
114 : virtual void describeFixedProperties(
115 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
116 : ) const;
117 : virtual void describeAggregateProperties(
118 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
119 : ) const;
120 :
121 : // XEventListener
122 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
123 :
124 : // OPropertyChangeListener
125 : virtual void _propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvt ) throw ( ::com::sun::star::uno::RuntimeException );
126 :
127 : // prevent method hiding
128 : using OBoundControlModel::getFastPropertyValue;
129 : using OBoundControlModel::setPropertyValues;
130 :
131 : protected:
132 : // OBoundControlModel overridables
133 : virtual ::com::sun::star::uno::Any
134 : translateDbColumnToControlValue( );
135 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
136 : getSupportedBindingTypes();
137 : virtual ::com::sun::star::uno::Any
138 : translateExternalValueToControlValue( const ::com::sun::star::uno::Any& _rExternalValue ) const;
139 : virtual ::com::sun::star::uno::Any
140 : translateControlValueToExternalValue( ) const;
141 : virtual sal_Bool commitControlValueToDbColumn( bool _bPostReset );
142 :
143 : virtual void onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
144 : virtual void onDisconnectedDbColumn();
145 :
146 : virtual ::com::sun::star::uno::Any
147 : getDefaultForReset() const;
148 : virtual void resetNoBroadcast();
149 :
150 : virtual ::com::sun::star::uno::Any
151 : getCurrentFormComponentValue() const;
152 :
153 : // OEntryListHelper overriables
154 : virtual void stringItemListChanged( ControlModelLock& _rInstanceLock );
155 : virtual void connectedExternalListSource( );
156 : virtual void disconnectedExternalListSource( );
157 : virtual void refreshInternalEntryList();
158 :
159 : protected:
160 : DECLARE_XCLONEABLE();
161 :
162 : private:
163 : void loadData( bool _bForce );
164 :
165 : /** refreshes the list boxes list data
166 : @precond we don't actually have an external list source
167 : */
168 : void impl_refreshDbEntryList( bool _bForce );
169 :
170 : void setBoundValues(const ValueList&);
171 : void clearBoundValues();
172 :
173 : ValueList impl_getValues() const;
174 :
175 : sal_Int32 getValueType() const;
176 :
177 : void convertBoundValues(sal_Int32 nType) const;
178 :
179 0 : bool impl_hasBoundComponent() const { return m_nBoundColumnType != ::com::sun::star::sdbc::DataType::SQLNULL; }
180 : };
181 :
182 : //==================================================================
183 : //= OListBoxControl
184 : //==================================================================
185 : typedef ::cppu::ImplHelper4 < ::com::sun::star::awt::XFocusListener
186 : , ::com::sun::star::awt::XItemListener
187 : , ::com::sun::star::awt::XListBox
188 : , ::com::sun::star::form::XChangeBroadcaster
189 : > OListBoxControl_BASE;
190 :
191 : class OListBoxControl :public OBoundControl
192 : ,public OListBoxControl_BASE
193 : ,public IEventProcessor
194 : {
195 : private:
196 : ::cppu::OInterfaceContainerHelper m_aChangeListeners;
197 : ::cppu::OInterfaceContainerHelper m_aItemListeners;
198 :
199 : ::com::sun::star::uno::Any m_aCurrentSelection;
200 : Timer m_aChangeTimer;
201 :
202 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XListBox >
203 : m_xAggregateListBox;
204 :
205 : ::rtl::Reference< ::comphelper::AsyncEventNotifier >
206 : m_pItemBroadcaster;
207 :
208 : protected:
209 : // UNO Anbindung
210 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
211 :
212 : public:
213 : OListBoxControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
214 : virtual ~OListBoxControl();
215 :
216 : // UNO Anbindung
217 0 : DECLARE_UNO3_AGG_DEFAULTS(OListBoxControl, OBoundControl);
218 : virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
219 :
220 : // XServiceInfo
221 0 : IMPLEMENTATION_NAME(OListBoxControl);
222 : virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
223 :
224 : // XChangeBroadcaster
225 : virtual void SAL_CALL addChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
226 : virtual void SAL_CALL removeChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
227 :
228 : // XFocusListener
229 : virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
230 : virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
231 :
232 : // XItemListener
233 : virtual void SAL_CALL itemStateChanged(const ::com::sun::star::awt::ItemEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
234 :
235 : // XEventListener
236 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
237 :
238 : // OComponentHelper
239 : virtual void SAL_CALL disposing();
240 :
241 : // XListBox
242 : virtual void SAL_CALL addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException);
243 : virtual void SAL_CALL removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException);
244 : virtual void SAL_CALL addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l ) throw (::com::sun::star::uno::RuntimeException);
245 : virtual void SAL_CALL removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l ) throw (::com::sun::star::uno::RuntimeException);
246 : virtual void SAL_CALL addItem( const ::rtl::OUString& aItem, ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
247 : virtual void SAL_CALL addItems( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aItems, ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
248 : virtual void SAL_CALL removeItems( ::sal_Int16 nPos, ::sal_Int16 nCount ) throw (::com::sun::star::uno::RuntimeException);
249 : virtual ::sal_Int16 SAL_CALL getItemCount( ) throw (::com::sun::star::uno::RuntimeException);
250 : virtual ::rtl::OUString SAL_CALL getItem( ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
251 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getItems( ) throw (::com::sun::star::uno::RuntimeException);
252 : virtual ::sal_Int16 SAL_CALL getSelectedItemPos( ) throw (::com::sun::star::uno::RuntimeException);
253 : virtual ::com::sun::star::uno::Sequence< ::sal_Int16 > SAL_CALL getSelectedItemsPos( ) throw (::com::sun::star::uno::RuntimeException);
254 : virtual ::rtl::OUString SAL_CALL getSelectedItem( ) throw (::com::sun::star::uno::RuntimeException);
255 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedItems( ) throw (::com::sun::star::uno::RuntimeException);
256 : virtual void SAL_CALL selectItemPos( ::sal_Int16 nPos, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
257 : virtual void SAL_CALL selectItemsPos( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& aPositions, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
258 : virtual void SAL_CALL selectItem( const ::rtl::OUString& aItem, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
259 : virtual ::sal_Bool SAL_CALL isMutipleMode( ) throw (::com::sun::star::uno::RuntimeException);
260 : virtual void SAL_CALL setMultipleMode( ::sal_Bool bMulti ) throw (::com::sun::star::uno::RuntimeException);
261 : virtual ::sal_Int16 SAL_CALL getDropDownLineCount( ) throw (::com::sun::star::uno::RuntimeException);
262 : virtual void SAL_CALL setDropDownLineCount( ::sal_Int16 nLines ) throw (::com::sun::star::uno::RuntimeException);
263 : virtual void SAL_CALL makeVisible( ::sal_Int16 nEntry ) throw (::com::sun::star::uno::RuntimeException);
264 :
265 : protected:
266 : // IEventProcessor
267 : virtual void processEvent( const ::comphelper::AnyEvent& _rEvent );
268 :
269 : private:
270 : DECL_LINK( OnTimeout, void* );
271 : };
272 :
273 : //.........................................................................
274 : }
275 : //.........................................................................
276 :
277 : #endif // _FORMS_LISTBOX_HXX_
278 :
279 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|