xref: /aoo42x/main/forms/source/component/ListBox.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _FORMS_LISTBOX_HXX_
29 #define _FORMS_LISTBOX_HXX_
30 
31 #include "FormComponent.hxx"
32 #include "cachedrowset.hxx"
33 #include "errorbroadcaster.hxx"
34 #include "entrylisthelper.hxx"
35 
36 /** === begin UNO includes === **/
37 #include <com/sun/star/util/XNumberFormatter.hpp>
38 #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
39 #include <com/sun/star/form/ListSourceType.hpp>
40 #include <com/sun/star/awt/XItemListener.hpp>
41 #include <com/sun/star/awt/XFocusListener.hpp>
42 #include <com/sun/star/awt/XListBox.hpp>
43 #include <com/sun/star/form/XChangeBroadcaster.hpp>
44 #include <com/sun/star/sdbc/DataType.hpp>
45 /** === end UNO includes === **/
46 
47 #include <comphelper/asyncnotification.hxx>
48 #include <connectivity/FValue.hxx>
49 #include <cppuhelper/interfacecontainer.hxx>
50 #include <cppuhelper/implbase1.hxx>
51 #include <vcl/timer.hxx>
52 
53 #include <vector>
54 
55 namespace dbtools
56 {
57     class FormattedColumnValue;
58 }
59 
60 //.........................................................................
61 namespace frm
62 {
63 
64 //==================================================================
65 //= OListBoxModel
66 //==================================================================
67 typedef ::std::vector< ::connectivity::ORowSetValue >   ValueList;
68 
69 class OListBoxModel :public OBoundControlModel
70                     ,public OEntryListHelper
71 					,public OErrorBroadcaster
72 {
73 
74     CachedRowSet                                m_aListRowSet;          // the row set to fill the list
75     ::connectivity::ORowSetValue                m_aSaveValue;
76 
77 	// <properties>
78 	::com::sun::star::form::ListSourceType		m_eListSourceType;		// type der list source
79 	::com::sun::star::uno::Any					m_aBoundColumn;
80     ValueList                                   m_aListSourceValues;
81     ValueList                                   m_aBoundValues;
82 	::com::sun::star::uno::Sequence<sal_Int16>	m_aDefaultSelectSeq;	// DefaultSelected
83 	// </properties>
84 
85 	sal_Int16				                    m_nNULLPos;             // position of the NULL value in our list
86     sal_Int32                                   m_nBoundColumnType;
87 
88 private:
89     ::connectivity::ORowSetValue getFirstSelectedValue() const;
90 
91 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>	_getTypes();
92 
93 public:
94 	DECLARE_DEFAULT_LEAF_XTOR( OListBoxModel );
95 
96 // XServiceInfo
97 	IMPLEMENTATION_NAME(OListBoxModel);
98 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
99 
100 // UNO Anbindung
101 	DECLARE_UNO3_AGG_DEFAULTS(OListBoxModel, OBoundControlModel);
102 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
103 
104 // OComponentHelper
105 	virtual void SAL_CALL disposing();
106 
107 // OPropertySetHelper
108 	virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
109 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
110 				throw (::com::sun::star::uno::Exception);
111 	virtual sal_Bool SAL_CALL convertFastPropertyValue(
112 				::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
113 				throw (::com::sun::star::lang::IllegalArgumentException);
114 
115 protected:
116     // XMultiPropertySet
117     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);
118 
119     // XPersistObject
120 	virtual ::rtl::OUString SAL_CALL	getServiceName() throw(::com::sun::star::uno::RuntimeException);
121 	virtual void SAL_CALL
122 		write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
123 	virtual void SAL_CALL
124 		read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
125 
126     // OControlModel's property handling
127 	virtual void describeFixedProperties(
128 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
129     ) const;
130     virtual void describeAggregateProperties(
131 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
132     ) const;
133 
134     // XEventListener
135 	virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
136 
137     // OPropertyChangeListener
138 	virtual void    _propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvt ) throw ( ::com::sun::star::uno::RuntimeException );
139 
140     // prevent method hiding
141     using OBoundControlModel::getFastPropertyValue;
142     using OBoundControlModel::setPropertyValues;
143 
144 protected:
145     // OBoundControlModel overridables
146     virtual ::com::sun::star::uno::Any
147                             translateDbColumnToControlValue( );
148     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
149                             getSupportedBindingTypes();
150     virtual ::com::sun::star::uno::Any
151                             translateExternalValueToControlValue( const ::com::sun::star::uno::Any& _rExternalValue ) const;
152     virtual ::com::sun::star::uno::Any
153                             translateControlValueToExternalValue( ) const;
154     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
155 
156     virtual void		    onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
157 	virtual void		    onDisconnectedDbColumn();
158 
159     virtual ::com::sun::star::uno::Any
160                             getDefaultForReset() const;
161 	virtual void            resetNoBroadcast();
162 
163     virtual ::com::sun::star::uno::Any
164                             getCurrentFormComponentValue() const;
165 
166     // OEntryListHelper overriables
167     virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock );
168     virtual void    connectedExternalListSource( );
169     virtual void    disconnectedExternalListSource( );
170     virtual void    refreshInternalEntryList();
171 
172 protected:
173 	DECLARE_XCLONEABLE();
174 
175 private:
176     void        loadData( bool _bForce );
177 
178     /** refreshes the list boxes list data
179         @precond we don't actually have an external list source
180     */
181     void        impl_refreshDbEntryList( bool _bForce );
182 
183     ValueList   impl_getValues() const;
184 
185     bool        impl_hasBoundComponent() const { return m_nBoundColumnType != ::com::sun::star::sdbc::DataType::SQLNULL; }
186 };
187 
188 //==================================================================
189 //= OListBoxControl
190 //==================================================================
191 typedef ::cppu::ImplHelper4 <   ::com::sun::star::awt::XFocusListener
192                             ,   ::com::sun::star::awt::XItemListener
193                             ,   ::com::sun::star::awt::XListBox
194                             ,   ::com::sun::star::form::XChangeBroadcaster
195                             >   OListBoxControl_BASE;
196 
197 class ChangeListeners;
198 
199 class OListBoxControl	:public OBoundControl
200 						,public OListBoxControl_BASE
201                         ,public IEventProcessor
202 {
203 private:
204     ::cppu::OInterfaceContainerHelper       m_aChangeListeners;
205     ::cppu::OInterfaceContainerHelper       m_aItemListeners;
206 
207 	::com::sun::star::uno::Any				m_aCurrentSelection;
208 	Timer									m_aChangeTimer;
209 
210     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XListBox >
211                                             m_xAggregateListBox;
212 
213     ::rtl::Reference< ::comphelper::AsyncEventNotifier >
214                                             m_pItemBroadcaster;
215 
216 protected:
217 	// UNO Anbindung
218 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>	_getTypes();
219 
220 public:
221 	OListBoxControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
222 	virtual ~OListBoxControl();
223 
224 	// UNO Anbindung
225 	DECLARE_UNO3_AGG_DEFAULTS(OListBoxControl, OBoundControl);
226 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
227 
228 // XServiceInfo
229 	IMPLEMENTATION_NAME(OListBoxControl);
230 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
231 
232 // XChangeBroadcaster
233     	virtual void SAL_CALL addChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
234 	virtual void SAL_CALL removeChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
235 
236 // XFocusListener
237 	virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
238 	virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
239 
240 // XItemListener
241 	virtual void SAL_CALL itemStateChanged(const ::com::sun::star::awt::ItemEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
242 
243 // XEventListener
244 	virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
245 
246 // OComponentHelper
247 	virtual void SAL_CALL disposing();
248 
249 // XListBox
250     virtual void SAL_CALL addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException);
251     virtual void SAL_CALL removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException);
252     virtual void SAL_CALL addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l ) throw (::com::sun::star::uno::RuntimeException);
253     virtual void SAL_CALL removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l ) throw (::com::sun::star::uno::RuntimeException);
254     virtual void SAL_CALL addItem( const ::rtl::OUString& aItem, ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
255     virtual void SAL_CALL addItems( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aItems, ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
256     virtual void SAL_CALL removeItems( ::sal_Int16 nPos, ::sal_Int16 nCount ) throw (::com::sun::star::uno::RuntimeException);
257     virtual ::sal_Int16 SAL_CALL getItemCount(  ) throw (::com::sun::star::uno::RuntimeException);
258     virtual ::rtl::OUString SAL_CALL getItem( ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
259     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getItems(  ) throw (::com::sun::star::uno::RuntimeException);
260     virtual ::sal_Int16 SAL_CALL getSelectedItemPos(  ) throw (::com::sun::star::uno::RuntimeException);
261     virtual ::com::sun::star::uno::Sequence< ::sal_Int16 > SAL_CALL getSelectedItemsPos(  ) throw (::com::sun::star::uno::RuntimeException);
262     virtual ::rtl::OUString SAL_CALL getSelectedItem(  ) throw (::com::sun::star::uno::RuntimeException);
263     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedItems(  ) throw (::com::sun::star::uno::RuntimeException);
264     virtual void SAL_CALL selectItemPos( ::sal_Int16 nPos, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
265     virtual void SAL_CALL selectItemsPos( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& aPositions, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
266     virtual void SAL_CALL selectItem( const ::rtl::OUString& aItem, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
267     virtual ::sal_Bool SAL_CALL isMutipleMode(  ) throw (::com::sun::star::uno::RuntimeException);
268     virtual void SAL_CALL setMultipleMode( ::sal_Bool bMulti ) throw (::com::sun::star::uno::RuntimeException);
269     virtual ::sal_Int16 SAL_CALL getDropDownLineCount(  ) throw (::com::sun::star::uno::RuntimeException);
270     virtual void SAL_CALL setDropDownLineCount( ::sal_Int16 nLines ) throw (::com::sun::star::uno::RuntimeException);
271     virtual void SAL_CALL makeVisible( ::sal_Int16 nEntry ) throw (::com::sun::star::uno::RuntimeException);
272 
273 protected:
274     // IEventProcessor
275     virtual void processEvent( const ::comphelper::AnyEvent& _rEvent );
276 
277 private:
278 	DECL_LINK( OnTimeout, void* );
279 };
280 
281 //.........................................................................
282 }
283 //.........................................................................
284 
285 #endif // _FORMS_LISTBOX_HXX_
286 
287