xref: /trunk/main/forms/source/component/ListBox.hxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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();
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 );
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     virtual sal_Bool SAL_CALL convertFastPropertyValue(
107                 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue );
108 
109 protected:
110     // XMultiPropertySet
111     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);
112 
113     // XPersistObject
114     virtual ::rtl::OUString SAL_CALL    getServiceName();
115     virtual void SAL_CALL
116         write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
117     virtual void SAL_CALL
118         read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
119 
120     // OControlModel's property handling
121     virtual void describeFixedProperties(
122         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
123     ) const;
124     virtual void describeAggregateProperties(
125         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
126     ) const;
127 
128     // XEventListener
129     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source);
130 
131     // OPropertyChangeListener
132     virtual void    _propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvt );
133 
134     // prevent method hiding
135     using OBoundControlModel::getFastPropertyValue;
136     using OBoundControlModel::setPropertyValues;
137 
138 protected:
139     // OBoundControlModel overridables
140     virtual ::com::sun::star::uno::Any
141                             translateDbColumnToControlValue( );
142     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
143                             getSupportedBindingTypes();
144     virtual ::com::sun::star::uno::Any
145                             translateExternalValueToControlValue( const ::com::sun::star::uno::Any& _rExternalValue ) const;
146     virtual ::com::sun::star::uno::Any
147                             translateControlValueToExternalValue( ) const;
148     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
149 
150     virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
151     virtual void            onDisconnectedDbColumn();
152 
153     virtual ::com::sun::star::uno::Any
154                             getDefaultForReset() const;
155     virtual void            resetNoBroadcast();
156 
157     virtual ::com::sun::star::uno::Any
158                             getCurrentFormComponentValue() const;
159 
160     // OEntryListHelper overriables
161     virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock );
162     virtual void    connectedExternalListSource( );
163     virtual void    disconnectedExternalListSource( );
164     virtual void    refreshInternalEntryList();
165 
166 protected:
167     DECLARE_XCLONEABLE();
168 
169 private:
170     void        loadData( bool _bForce );
171 
172     /** refreshes the list boxes list data
173         @precond we don't actually have an external list source
174     */
175     void        impl_refreshDbEntryList( bool _bForce );
176 
177     ValueList   impl_getValues() const;
178 
179     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 ChangeListeners;
192 
193 class OListBoxControl   :public OBoundControl
194                         ,public OListBoxControl_BASE
195                         ,public IEventProcessor
196 {
197 private:
198     ::cppu::OInterfaceContainerHelper       m_aChangeListeners;
199     ::cppu::OInterfaceContainerHelper       m_aItemListeners;
200 
201     ::com::sun::star::uno::Any              m_aCurrentSelection;
202     Timer                                   m_aChangeTimer;
203 
204     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XListBox >
205                                             m_xAggregateListBox;
206 
207     ::rtl::Reference< ::comphelper::AsyncEventNotifier >
208                                             m_pItemBroadcaster;
209 
210 protected:
211     // UNO Anbindung
212     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>   _getTypes();
213 
214 public:
215     OListBoxControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
216     virtual ~OListBoxControl();
217 
218     // UNO Anbindung
219     DECLARE_UNO3_AGG_DEFAULTS(OListBoxControl, OBoundControl);
220     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType );
221 
222 // XServiceInfo
223     IMPLEMENTATION_NAME(OListBoxControl);
224     virtual StringSequence SAL_CALL getSupportedServiceNames();
225 
226 // XChangeBroadcaster
227         virtual void SAL_CALL addChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener);
228     virtual void SAL_CALL removeChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener);
229 
230 // XFocusListener
231     virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& _rEvent);
232     virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& _rEvent);
233 
234 // XItemListener
235     virtual void SAL_CALL itemStateChanged(const ::com::sun::star::awt::ItemEvent& _rEvent);
236 
237 // XEventListener
238     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source);
239 
240 // OComponentHelper
241     virtual void SAL_CALL disposing();
242 
243 // XListBox
244     virtual void SAL_CALL addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l );
245     virtual void SAL_CALL removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l );
246     virtual void SAL_CALL addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l );
247     virtual void SAL_CALL removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l );
248     virtual void SAL_CALL addItem( const ::rtl::OUString& aItem, ::sal_Int16 nPos );
249     virtual void SAL_CALL addItems( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aItems, ::sal_Int16 nPos );
250     virtual void SAL_CALL removeItems( ::sal_Int16 nPos, ::sal_Int16 nCount );
251     virtual ::sal_Int16 SAL_CALL getItemCount(  );
252     virtual ::rtl::OUString SAL_CALL getItem( ::sal_Int16 nPos );
253     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getItems(  );
254     virtual ::sal_Int16 SAL_CALL getSelectedItemPos(  );
255     virtual ::com::sun::star::uno::Sequence< ::sal_Int16 > SAL_CALL getSelectedItemsPos(  );
256     virtual ::rtl::OUString SAL_CALL getSelectedItem(  );
257     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedItems(  );
258     virtual void SAL_CALL selectItemPos( ::sal_Int16 nPos, ::sal_Bool bSelect );
259     virtual void SAL_CALL selectItemsPos( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& aPositions, ::sal_Bool bSelect );
260     virtual void SAL_CALL selectItem( const ::rtl::OUString& aItem, ::sal_Bool bSelect );
261     virtual ::sal_Bool SAL_CALL isMutipleMode(  );
262     virtual void SAL_CALL setMultipleMode( ::sal_Bool bMulti );
263     virtual ::sal_Int16 SAL_CALL getDropDownLineCount(  );
264     virtual void SAL_CALL setDropDownLineCount( ::sal_Int16 nLines );
265     virtual void SAL_CALL makeVisible( ::sal_Int16 nEntry );
266 
267 protected:
268     // IEventProcessor
269     virtual void processEvent( const ::comphelper::AnyEvent& _rEvent );
270 
271 private:
272     DECL_LINK( OnTimeout, void* );
273 };
274 
275 //.........................................................................
276 }
277 //.........................................................................
278 
279 #endif // _FORMS_LISTBOX_HXX_
280