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