xref: /AOO41X/main/forms/source/component/ListBox.hxx (revision 2d785d7ea953737df3731803a26e291d82066c5a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _FORMS_LISTBOX_HXX_
25 #define _FORMS_LISTBOX_HXX_
26 
27 #include "FormComponent.hxx"
28 #include "cachedrowset.hxx"
29 #include "errorbroadcaster.hxx"
30 #include "entrylisthelper.hxx"
31 
32 /** === begin UNO includes === **/
33 #include <com/sun/star/util/XNumberFormatter.hpp>
34 #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
35 #include <com/sun/star/form/ListSourceType.hpp>
36 #include <com/sun/star/awt/XItemListener.hpp>
37 #include <com/sun/star/awt/XFocusListener.hpp>
38 #include <com/sun/star/awt/XListBox.hpp>
39 #include <com/sun/star/form/XChangeBroadcaster.hpp>
40 #include <com/sun/star/sdbc/DataType.hpp>
41 /** === end UNO includes === **/
42 
43 #include <comphelper/asyncnotification.hxx>
44 #include <connectivity/FValue.hxx>
45 #include <cppuhelper/interfacecontainer.hxx>
46 #include <cppuhelper/implbase1.hxx>
47 #include <vcl/timer.hxx>
48 
49 #include <vector>
50 
51 namespace dbtools
52 {
53     class FormattedColumnValue;
54 }
55 
56 //.........................................................................
57 namespace frm
58 {
59 
60 //==================================================================
61 //= OListBoxModel
62 //==================================================================
63 typedef ::std::vector< ::connectivity::ORowSetValue >   ValueList;
64 
65 class OListBoxModel :public OBoundControlModel
66                     ,public OEntryListHelper
67                     ,public OErrorBroadcaster
68 {
69 
70     CachedRowSet                                m_aListRowSet;          // the row set to fill the list
71     ::connectivity::ORowSetValue                m_aSaveValue;
72 
73     // <properties>
74     ::com::sun::star::form::ListSourceType      m_eListSourceType;      // type der list source
75     ::com::sun::star::uno::Any                  m_aBoundColumn;
76     ValueList                                   m_aListSourceValues;
77     ValueList                                   m_aBoundValues;
78     ::com::sun::star::uno::Sequence<sal_Int16>  m_aDefaultSelectSeq;    // DefaultSelected
79     // </properties>
80 
81     sal_Int16                                   m_nNULLPos;             // position of the NULL value in our list
82     sal_Int32                                   m_nBoundColumnType;
83 
84 private:
85     ::connectivity::ORowSetValue getFirstSelectedValue() const;
86 
87     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>   _getTypes();
88 
89 public:
90     DECLARE_DEFAULT_LEAF_XTOR( OListBoxModel );
91 
92 // XServiceInfo
93     IMPLEMENTATION_NAME(OListBoxModel);
94     virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
95 
96 // UNO Anbindung
97     DECLARE_UNO3_AGG_DEFAULTS(OListBoxModel, OBoundControlModel);
98     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
99 
100 // OComponentHelper
101     virtual void SAL_CALL disposing();
102 
103 // OPropertySetHelper
104     virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
105     virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
106                 throw (::com::sun::star::uno::Exception);
107     virtual sal_Bool SAL_CALL convertFastPropertyValue(
108                 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
109                 throw (::com::sun::star::lang::IllegalArgumentException);
110 
111 protected:
112     // XMultiPropertySet
113     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);
114 
115     // XPersistObject
116     virtual ::rtl::OUString SAL_CALL    getServiceName() throw(::com::sun::star::uno::RuntimeException);
117     virtual void SAL_CALL
118         write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
119     virtual void SAL_CALL
120         read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
121 
122     // OControlModel's property handling
123     virtual void describeFixedProperties(
124         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
125     ) const;
126     virtual void describeAggregateProperties(
127         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
128     ) const;
129 
130     // XEventListener
131     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
132 
133     // OPropertyChangeListener
134     virtual void    _propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvt ) throw ( ::com::sun::star::uno::RuntimeException );
135 
136     // prevent method hiding
137     using OBoundControlModel::getFastPropertyValue;
138     using OBoundControlModel::setPropertyValues;
139 
140 protected:
141     // OBoundControlModel overridables
142     virtual ::com::sun::star::uno::Any
143                             translateDbColumnToControlValue( );
144     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
145                             getSupportedBindingTypes();
146     virtual ::com::sun::star::uno::Any
147                             translateExternalValueToControlValue( const ::com::sun::star::uno::Any& _rExternalValue ) const;
148     virtual ::com::sun::star::uno::Any
149                             translateControlValueToExternalValue( ) const;
150     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
151 
152     virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
153     virtual void            onDisconnectedDbColumn();
154 
155     virtual ::com::sun::star::uno::Any
156                             getDefaultForReset() const;
157     virtual void            resetNoBroadcast();
158 
159     virtual ::com::sun::star::uno::Any
160                             getCurrentFormComponentValue() const;
161 
162     // OEntryListHelper overriables
163     virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock );
164     virtual void    connectedExternalListSource( );
165     virtual void    disconnectedExternalListSource( );
166     virtual void    refreshInternalEntryList();
167 
168 protected:
169     DECLARE_XCLONEABLE();
170 
171 private:
172     void        loadData( bool _bForce );
173 
174     /** refreshes the list boxes list data
175         @precond we don't actually have an external list source
176     */
177     void        impl_refreshDbEntryList( bool _bForce );
178 
179     ValueList   impl_getValues() const;
180 
impl_hasBoundComponent() const181     bool        impl_hasBoundComponent() const { return m_nBoundColumnType != ::com::sun::star::sdbc::DataType::SQLNULL; }
182 };
183 
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;
192 
193 class ChangeListeners;
194 
195 class OListBoxControl   :public OBoundControl
196                         ,public OListBoxControl_BASE
197                         ,public IEventProcessor
198 {
199 private:
200     ::cppu::OInterfaceContainerHelper       m_aChangeListeners;
201     ::cppu::OInterfaceContainerHelper       m_aItemListeners;
202 
203     ::com::sun::star::uno::Any              m_aCurrentSelection;
204     Timer                                   m_aChangeTimer;
205 
206     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XListBox >
207                                             m_xAggregateListBox;
208 
209     ::rtl::Reference< ::comphelper::AsyncEventNotifier >
210                                             m_pItemBroadcaster;
211 
212 protected:
213     // UNO Anbindung
214     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>   _getTypes();
215 
216 public:
217     OListBoxControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
218     virtual ~OListBoxControl();
219 
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);
223 
224 // XServiceInfo
225     IMPLEMENTATION_NAME(OListBoxControl);
226     virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
227 
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);
231 
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);
235 
236 // XItemListener
237     virtual void SAL_CALL itemStateChanged(const ::com::sun::star::awt::ItemEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
238 
239 // XEventListener
240     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
241 
242 // OComponentHelper
243     virtual void SAL_CALL disposing();
244 
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);
268 
269 protected:
270     // IEventProcessor
271     virtual void processEvent( const ::comphelper::AnyEvent& _rEvent );
272 
273 private:
274     DECL_LINK( OnTimeout, void* );
275 };
276 
277 //.........................................................................
278 }
279 //.........................................................................
280 
281 #endif // _FORMS_LISTBOX_HXX_
282 
283