xref: /aoo42x/main/forms/source/component/ListBox.cxx (revision 07a3d7f1)
124acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
324acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
424acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
524acc546SAndrew Rist  * distributed with this work for additional information
624acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
724acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
824acc546SAndrew Rist  * "License"); you may not use this file except in compliance
924acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
1024acc546SAndrew Rist  *
1124acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1224acc546SAndrew Rist  *
1324acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1424acc546SAndrew Rist  * software distributed under the License is distributed on an
1524acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1624acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
1724acc546SAndrew Rist  * specific language governing permissions and limitations
1824acc546SAndrew Rist  * under the License.
1924acc546SAndrew Rist  *
2024acc546SAndrew Rist  *************************************************************/
2124acc546SAndrew Rist 
2224acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "ListBox.hxx"
28cdf0e10cSrcweir #include "property.hxx"
29cdf0e10cSrcweir #include "property.hrc"
30cdf0e10cSrcweir #include "services.hxx"
31cdf0e10cSrcweir #include "frm_resource.hxx"
32cdf0e10cSrcweir #include "frm_resource.hrc"
33cdf0e10cSrcweir #include "BaseListBox.hxx"
34cdf0e10cSrcweir #include "listenercontainers.hxx"
35cdf0e10cSrcweir #include "componenttools.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /** === begin UNO includes === **/
38cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp>
40cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
43cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp>
44cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
47cdf0e10cSrcweir /** === end UNO includes === **/
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <comphelper/basicio.hxx>
50cdf0e10cSrcweir #include <comphelper/container.hxx>
51cdf0e10cSrcweir #include <comphelper/numbers.hxx>
52cdf0e10cSrcweir #include <comphelper/listenernotification.hxx>
53cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
54cdf0e10cSrcweir #include <connectivity/formattedcolumnvalue.hxx>
55cdf0e10cSrcweir #include <connectivity/dbconversion.hxx>
56cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
57cdf0e10cSrcweir #include <rtl/logfile.hxx>
58cdf0e10cSrcweir #include <tools/debug.hxx>
59cdf0e10cSrcweir #include <tools/diagnose_ex.h>
60cdf0e10cSrcweir #include <unotools/sharedunocomponent.hxx>
61cdf0e10cSrcweir #include <vcl/svapp.hxx>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include <boost/optional.hpp>
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #include <algorithm>
66cdf0e10cSrcweir #include <functional>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //.........................................................................
70cdf0e10cSrcweir namespace frm
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
73cdf0e10cSrcweir     using namespace ::com::sun::star::sdb;
74cdf0e10cSrcweir     using namespace ::com::sun::star::sdbc;
75cdf0e10cSrcweir     using namespace ::com::sun::star::sdbcx;
76cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
77cdf0e10cSrcweir     using namespace ::com::sun::star::container;
78cdf0e10cSrcweir     using namespace ::com::sun::star::form;
79cdf0e10cSrcweir     using namespace ::com::sun::star::awt;
80cdf0e10cSrcweir     using namespace ::com::sun::star::io;
81cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
82cdf0e10cSrcweir     using namespace ::com::sun::star::util;
83cdf0e10cSrcweir     using namespace ::com::sun::star::form::binding;
84cdf0e10cSrcweir     using namespace ::dbtools;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     using ::connectivity::ORowSetValue;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     //==============================================================================
89cdf0e10cSrcweir     //= helper
90cdf0e10cSrcweir     //==============================================================================
91cdf0e10cSrcweir     namespace
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         //--------------------------------------------------------------------------
94cdf0e10cSrcweir         struct RowSetValueToString : public ::std::unary_function< ORowSetValue, ::rtl::OUString >
95cdf0e10cSrcweir         {
operator ()frm::__anonfa98e5550111::RowSetValueToString96cdf0e10cSrcweir             ::rtl::OUString operator()( const ORowSetValue& _value ) const
97cdf0e10cSrcweir             {
98cdf0e10cSrcweir                 return _value.getString();
99cdf0e10cSrcweir             }
100cdf0e10cSrcweir         };
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         //--------------------------------------------------------------------------
103cdf0e10cSrcweir         struct AppendRowSetValueString : public ::std::unary_function< ::rtl::OUString, void >
104cdf0e10cSrcweir         {
AppendRowSetValueStringfrm::__anonfa98e5550111::AppendRowSetValueString105cdf0e10cSrcweir             AppendRowSetValueString( ::rtl::OUString& _string )
106cdf0e10cSrcweir                 :m_string( _string )
107cdf0e10cSrcweir             {
108cdf0e10cSrcweir             }
109cdf0e10cSrcweir 
operator ()frm::__anonfa98e5550111::AppendRowSetValueString110cdf0e10cSrcweir             void operator()( const ::rtl::OUString _append )
111cdf0e10cSrcweir             {
112cdf0e10cSrcweir                 m_string += _append;
113cdf0e10cSrcweir             }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         private:
116cdf0e10cSrcweir             ::rtl::OUString&    m_string;
117cdf0e10cSrcweir         };
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         //--------------------------------------------------------------------------
lcl_convertToStringSequence(const ValueList & _values)120cdf0e10cSrcweir         Sequence< ::rtl::OUString > lcl_convertToStringSequence( const ValueList& _values )
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             Sequence< ::rtl::OUString > aStrings( _values.size() );
123cdf0e10cSrcweir             ::std::transform(
124cdf0e10cSrcweir                 _values.begin(),
125cdf0e10cSrcweir                 _values.end(),
126cdf0e10cSrcweir                 aStrings.getArray(),
127cdf0e10cSrcweir                 RowSetValueToString()
128cdf0e10cSrcweir             );
129cdf0e10cSrcweir             return aStrings;
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     //==============================================================================
134cdf0e10cSrcweir     //= ItemEventDescription
135cdf0e10cSrcweir     //==============================================================================
136cdf0e10cSrcweir     typedef ::comphelper::EventHolder< ItemEvent >    ItemEventDescription;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     //==============================================================================
139cdf0e10cSrcweir     //= OListBoxModel
140cdf0e10cSrcweir     //==============================================================================
141cdf0e10cSrcweir     //------------------------------------------------------------------
OListBoxModel_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)142cdf0e10cSrcweir     InterfaceRef SAL_CALL OListBoxModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         return *(new OListBoxModel(_rxFactory));
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     //------------------------------------------------------------------------------
_getTypes()148cdf0e10cSrcweir     Sequence< Type> OListBoxModel::_getTypes()
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         return TypeBag(
151cdf0e10cSrcweir             OBoundControlModel::_getTypes(),
152cdf0e10cSrcweir             OEntryListHelper::getTypes(),
153cdf0e10cSrcweir             OErrorBroadcaster::getTypes()
154cdf0e10cSrcweir         ).getTypes();
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     DBG_NAME(OListBoxModel);
159cdf0e10cSrcweir     //------------------------------------------------------------------
OListBoxModel(const Reference<XMultiServiceFactory> & _rxFactory)160cdf0e10cSrcweir     OListBoxModel::OListBoxModel(const Reference<XMultiServiceFactory>& _rxFactory)
161cdf0e10cSrcweir         :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_LISTBOX, FRM_SUN_CONTROL_LISTBOX, sal_True, sal_True, sal_True )
162cdf0e10cSrcweir         // use the old control name for compytibility reasons
163cdf0e10cSrcweir         ,OEntryListHelper( (OControlModel&)*this )
164cdf0e10cSrcweir         ,OErrorBroadcaster( OComponentHelper::rBHelper )
165cdf0e10cSrcweir         ,m_aListRowSet( getContext() )
166cdf0e10cSrcweir         ,m_nNULLPos(-1)
167cdf0e10cSrcweir         ,m_nBoundColumnType( DataType::SQLNULL )
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         DBG_CTOR(OListBoxModel,NULL);
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         m_nClassId = FormComponentType::LISTBOX;
172cdf0e10cSrcweir         m_eListSourceType = ListSourceType_VALUELIST;
173cdf0e10cSrcweir         m_aBoundColumn <<= (sal_Int16)1;
174cdf0e10cSrcweir         initValueProperty( PROPERTY_SELECT_SEQ, PROPERTY_ID_SELECT_SEQ);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         startAggregatePropertyListening( PROPERTY_STRINGITEMLIST );
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     //------------------------------------------------------------------
OListBoxModel(const OListBoxModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)180cdf0e10cSrcweir     OListBoxModel::OListBoxModel( const OListBoxModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
181cdf0e10cSrcweir         :OBoundControlModel( _pOriginal, _rxFactory )
182cdf0e10cSrcweir         ,OEntryListHelper( *_pOriginal, (OControlModel&)*this )
183cdf0e10cSrcweir         ,OErrorBroadcaster( OComponentHelper::rBHelper )
184cdf0e10cSrcweir         ,m_aListRowSet( getContext() )
185cdf0e10cSrcweir         ,m_eListSourceType( _pOriginal->m_eListSourceType )
186cdf0e10cSrcweir         ,m_aBoundColumn( _pOriginal->m_aBoundColumn )
187cdf0e10cSrcweir         ,m_aListSourceValues( _pOriginal->m_aListSourceValues )
188cdf0e10cSrcweir         ,m_aBoundValues( _pOriginal->m_aBoundValues )
189cdf0e10cSrcweir         ,m_aDefaultSelectSeq( _pOriginal->m_aDefaultSelectSeq )
190cdf0e10cSrcweir         ,m_nNULLPos(-1)
191cdf0e10cSrcweir         ,m_nBoundColumnType( DataType::SQLNULL )
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         DBG_CTOR(OListBoxModel,NULL);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         startAggregatePropertyListening( PROPERTY_STRINGITEMLIST );
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     //------------------------------------------------------------------
~OListBoxModel()199cdf0e10cSrcweir     OListBoxModel::~OListBoxModel()
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         if (!OComponentHelper::rBHelper.bDisposed)
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             acquire();
204cdf0e10cSrcweir             dispose();
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         DBG_DTOR(OListBoxModel,NULL);
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     // XCloneable
211cdf0e10cSrcweir     //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(OListBoxModel)212cdf0e10cSrcweir     IMPLEMENT_DEFAULT_CLONING( OListBoxModel )
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     // XServiceInfo
215cdf0e10cSrcweir     //------------------------------------------------------------------------------
216cdf0e10cSrcweir     StringSequence SAL_CALL OListBoxModel::getSupportedServiceNames() throw(RuntimeException)
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         sal_Int32 nOldLen = aSupported.getLength();
221cdf0e10cSrcweir 	    aSupported.realloc( nOldLen + 8 );
222cdf0e10cSrcweir 	    ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir         *pStoreTo++ = BINDABLE_CONTROL_MODEL;
225cdf0e10cSrcweir         *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
226cdf0e10cSrcweir         *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
229cdf0e10cSrcweir         *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         *pStoreTo++ = FRM_SUN_COMPONENT_LISTBOX;
232cdf0e10cSrcweir         *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_LISTBOX;
233cdf0e10cSrcweir         *pStoreTo++ = BINDABLE_DATABASE_LIST_BOX;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         return aSupported;
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     //------------------------------------------------------------------------------
queryAggregation(const Type & _rType)239cdf0e10cSrcweir     Any SAL_CALL OListBoxModel::queryAggregation(const Type& _rType) throw (RuntimeException)
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         Any aReturn = OBoundControlModel::queryAggregation( _rType );
242cdf0e10cSrcweir         if ( !aReturn.hasValue() )
243cdf0e10cSrcweir             aReturn = OEntryListHelper::queryInterface( _rType );
244cdf0e10cSrcweir         if ( !aReturn.hasValue() )
245cdf0e10cSrcweir             aReturn = OErrorBroadcaster::queryInterface( _rType );
246cdf0e10cSrcweir         return aReturn;
247cdf0e10cSrcweir     }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     // OComponentHelper
250cdf0e10cSrcweir     //------------------------------------------------------------------------------
disposing()251cdf0e10cSrcweir     void OListBoxModel::disposing()
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         OBoundControlModel::disposing();
254cdf0e10cSrcweir         OEntryListHelper::disposing();
255cdf0e10cSrcweir         OErrorBroadcaster::disposing();
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     //------------------------------------------------------------------------------
getFastPropertyValue(Any & _rValue,sal_Int32 _nHandle) const259cdf0e10cSrcweir     void OListBoxModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         switch (_nHandle)
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir         case PROPERTY_ID_BOUNDCOLUMN:
264cdf0e10cSrcweir             _rValue <<= m_aBoundColumn;
265cdf0e10cSrcweir             break;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         case PROPERTY_ID_LISTSOURCETYPE:
268cdf0e10cSrcweir             _rValue <<= m_eListSourceType;
269cdf0e10cSrcweir             break;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         case PROPERTY_ID_LISTSOURCE:
272cdf0e10cSrcweir             _rValue <<= lcl_convertToStringSequence( m_aListSourceValues );
273cdf0e10cSrcweir             break;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         case PROPERTY_ID_VALUE_SEQ:
276cdf0e10cSrcweir             _rValue <<= lcl_convertToStringSequence( m_aBoundValues );
277cdf0e10cSrcweir             break;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         case PROPERTY_ID_DEFAULT_SELECT_SEQ:
280cdf0e10cSrcweir             _rValue <<= m_aDefaultSelectSeq;
281cdf0e10cSrcweir             break;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir         case PROPERTY_ID_STRINGITEMLIST:
284cdf0e10cSrcweir             _rValue <<= getStringItemList();
285cdf0e10cSrcweir             break;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir         default:
288cdf0e10cSrcweir             OBoundControlModel::getFastPropertyValue(_rValue, _nHandle);
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     //------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any & _rValue)293cdf0e10cSrcweir     void OListBoxModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (com::sun::star::uno::Exception)
294cdf0e10cSrcweir     {
295cdf0e10cSrcweir         switch (_nHandle)
296cdf0e10cSrcweir         {
297cdf0e10cSrcweir         case PROPERTY_ID_BOUNDCOLUMN :
298cdf0e10cSrcweir             DBG_ASSERT((_rValue.getValueType().getTypeClass() == TypeClass_SHORT) || (_rValue.getValueType().getTypeClass() == TypeClass_VOID),
299cdf0e10cSrcweir                 "OListBoxModel::setFastPropertyValue_NoBroadcast : invalid type !" );
300cdf0e10cSrcweir             m_aBoundColumn = _rValue;
301cdf0e10cSrcweir             break;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir         case PROPERTY_ID_LISTSOURCETYPE :
304cdf0e10cSrcweir             DBG_ASSERT(_rValue.getValueType().equals(::getCppuType(reinterpret_cast<ListSourceType*>(NULL))),
305cdf0e10cSrcweir                 "OComboBoxModel::setFastPropertyValue_NoBroadcast : invalid type !" );
306cdf0e10cSrcweir             _rValue >>= m_eListSourceType;
307cdf0e10cSrcweir             break;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         case PROPERTY_ID_LISTSOURCE:
310cdf0e10cSrcweir         {
311cdf0e10cSrcweir             // extract
312cdf0e10cSrcweir             Sequence< ::rtl::OUString > aListSource;
313cdf0e10cSrcweir             OSL_VERIFY( _rValue >>= aListSource );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir             // copy to member
316cdf0e10cSrcweir             ValueList().swap(m_aListSourceValues);
317cdf0e10cSrcweir             ::std::copy(
318cdf0e10cSrcweir                 aListSource.getConstArray(),
319cdf0e10cSrcweir                 aListSource.getConstArray() + aListSource.getLength(),
320cdf0e10cSrcweir                 ::std::insert_iterator< ValueList >( m_aListSourceValues, m_aListSourceValues.end() )
321cdf0e10cSrcweir             );
322cdf0e10cSrcweir 
323cdf0e10cSrcweir             // propagate
324cdf0e10cSrcweir             if ( m_eListSourceType == ListSourceType_VALUELIST )
325cdf0e10cSrcweir             {
326cdf0e10cSrcweir                 m_aBoundValues = m_aListSourceValues;
327cdf0e10cSrcweir             }
328cdf0e10cSrcweir             else
329cdf0e10cSrcweir             {
330cdf0e10cSrcweir                 if ( m_xCursor.is() && !hasField() && !hasExternalListSource() )
331cdf0e10cSrcweir                     // listbox is already connected to a database, and no external list source
332cdf0e10cSrcweir                     // data source changed -> refresh
333cdf0e10cSrcweir                     loadData( false );
334cdf0e10cSrcweir             }
335cdf0e10cSrcweir         }
336cdf0e10cSrcweir         break;
337cdf0e10cSrcweir 
338cdf0e10cSrcweir         case PROPERTY_ID_VALUE_SEQ :
339cdf0e10cSrcweir             OSL_ENSURE( false, "ValueItemList is read-only!" );
340cdf0e10cSrcweir             throw PropertyVetoException();
341cdf0e10cSrcweir 
342cdf0e10cSrcweir         case PROPERTY_ID_DEFAULT_SELECT_SEQ :
343cdf0e10cSrcweir             DBG_ASSERT(_rValue.getValueType().equals(::getCppuType(reinterpret_cast< Sequence<sal_Int16>*>(NULL))),
344cdf0e10cSrcweir                 "OListBoxModel::setFastPropertyValue_NoBroadcast : invalid type !" );
345cdf0e10cSrcweir             _rValue >>= m_aDefaultSelectSeq;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir             DBG_ASSERT(m_xAggregateFastSet.is(), "OListBoxModel::setFastPropertyValue_NoBroadcast(DEFAULT_SELECT_SEQ) : invalid aggregate !");
348cdf0e10cSrcweir             if ( m_xAggregateFastSet.is() )
349cdf0e10cSrcweir                 setControlValue( _rValue, eOther );
350cdf0e10cSrcweir             break;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         case PROPERTY_ID_STRINGITEMLIST:
353cdf0e10cSrcweir         {
354cdf0e10cSrcweir 			ControlModelLock aLock( *this );
355cdf0e10cSrcweir             setNewStringItemList( _rValue, aLock );
356cdf0e10cSrcweir                 // TODO: this is bogus. setNewStringItemList expects a guard which has the *only*
357cdf0e10cSrcweir                 // lock to the mutex, but setFastPropertyValue_NoBroadcast is already called with
358cdf0e10cSrcweir                 // a lock - so we effectively has two locks here, of which setNewStringItemList can
359cdf0e10cSrcweir                 // only control one.
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir         resetNoBroadcast();
362cdf0e10cSrcweir         break;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir         default:
365cdf0e10cSrcweir             OBoundControlModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
366cdf0e10cSrcweir         }
367cdf0e10cSrcweir     }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     //------------------------------------------------------------------------------
convertFastPropertyValue(Any & _rConvertedValue,Any & _rOldValue,sal_Int32 _nHandle,const Any & _rValue)370cdf0e10cSrcweir     sal_Bool OListBoxModel::convertFastPropertyValue(
371cdf0e10cSrcweir         Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue)
372cdf0e10cSrcweir         throw (IllegalArgumentException)
373cdf0e10cSrcweir     {
374cdf0e10cSrcweir         sal_Bool bModified(sal_False);
375cdf0e10cSrcweir         switch (_nHandle)
376cdf0e10cSrcweir         {
377cdf0e10cSrcweir         case PROPERTY_ID_BOUNDCOLUMN :
378cdf0e10cSrcweir             bModified = tryPropertyValue(_rConvertedValue, _rOldValue, _rValue, m_aBoundColumn, ::getCppuType(reinterpret_cast<sal_Int16*>(NULL)));
379cdf0e10cSrcweir             break;
380cdf0e10cSrcweir 
381cdf0e10cSrcweir         case PROPERTY_ID_LISTSOURCETYPE:
382cdf0e10cSrcweir             bModified = tryPropertyValueEnum(_rConvertedValue, _rOldValue, _rValue, m_eListSourceType);
383cdf0e10cSrcweir             break;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir         case PROPERTY_ID_LISTSOURCE:
386cdf0e10cSrcweir             bModified = tryPropertyValue(_rConvertedValue, _rOldValue, _rValue, lcl_convertToStringSequence( m_aListSourceValues ) );
387cdf0e10cSrcweir             break;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir         case PROPERTY_ID_VALUE_SEQ :
390cdf0e10cSrcweir             OSL_ENSURE( false, "ValueItemList is read-only!" );
391cdf0e10cSrcweir             throw PropertyVetoException();
392cdf0e10cSrcweir 
393cdf0e10cSrcweir         case PROPERTY_ID_DEFAULT_SELECT_SEQ :
394cdf0e10cSrcweir             bModified = tryPropertyValue(_rConvertedValue, _rOldValue, _rValue, m_aDefaultSelectSeq);
395cdf0e10cSrcweir             break;
396cdf0e10cSrcweir 
397cdf0e10cSrcweir         case PROPERTY_ID_STRINGITEMLIST:
398cdf0e10cSrcweir             bModified = convertNewListSourceProperty( _rConvertedValue, _rOldValue, _rValue );
399cdf0e10cSrcweir             break;
400cdf0e10cSrcweir 
401cdf0e10cSrcweir         default:
402cdf0e10cSrcweir             return OBoundControlModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
403cdf0e10cSrcweir         }
404cdf0e10cSrcweir         return bModified;
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     //------------------------------------------------------------------------------
setPropertyValues(const Sequence<::rtl::OUString> & _rPropertyNames,const Sequence<Any> & _rValues)408cdf0e10cSrcweir     void SAL_CALL OListBoxModel::setPropertyValues( const Sequence< ::rtl::OUString >& _rPropertyNames, const Sequence< Any >& _rValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
409cdf0e10cSrcweir     {
410cdf0e10cSrcweir         // if both SelectedItems and StringItemList are set, care for this
411cdf0e10cSrcweir         // #i27024# / 2004-04-05 / fs@openoffice.org
412cdf0e10cSrcweir         const Any* pSelectSequenceValue = NULL;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir         const ::rtl::OUString* pStartPos = _rPropertyNames.getConstArray();
415cdf0e10cSrcweir         const ::rtl::OUString* pEndPos   = _rPropertyNames.getConstArray() + _rPropertyNames.getLength();
416cdf0e10cSrcweir         const ::rtl::OUString* pSelectedItemsPos = ::std::find_if(
417cdf0e10cSrcweir             pStartPos, pEndPos,
418cdf0e10cSrcweir              ::std::bind2nd( ::std::equal_to< ::rtl::OUString >(), PROPERTY_SELECT_SEQ )
419cdf0e10cSrcweir         );
420cdf0e10cSrcweir         const ::rtl::OUString* pStringItemListPos = ::std::find_if(
421cdf0e10cSrcweir             pStartPos, pEndPos,
422cdf0e10cSrcweir              ::std::bind2nd( ::std::equal_to< ::rtl::OUString >(), PROPERTY_STRINGITEMLIST )
423cdf0e10cSrcweir         );
424cdf0e10cSrcweir         if ( ( pSelectedItemsPos != pEndPos ) && ( pStringItemListPos != pEndPos ) )
425cdf0e10cSrcweir         {
426cdf0e10cSrcweir             // both properties are present
427cdf0e10cSrcweir             // -> remember the value for the select sequence
428cdf0e10cSrcweir             pSelectSequenceValue = _rValues.getConstArray() + ( pSelectedItemsPos - pStartPos );
429cdf0e10cSrcweir         }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir         OBoundControlModel::setPropertyValues( _rPropertyNames, _rValues );
432cdf0e10cSrcweir 
433cdf0e10cSrcweir         if ( pSelectSequenceValue )
434cdf0e10cSrcweir         {
435cdf0e10cSrcweir             setPropertyValue( PROPERTY_SELECT_SEQ, *pSelectSequenceValue );
436cdf0e10cSrcweir             // Note that this is the only reliable way, since one of the properties is implemented
437cdf0e10cSrcweir             // by ourself, and one is implemented by the aggregate, we cannot rely on any particular
438cdf0e10cSrcweir             // results when setting them both - too many undocumented behavior in all the involved
439cdf0e10cSrcweir             // classes
440cdf0e10cSrcweir         }
441cdf0e10cSrcweir     }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir     //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const444cdf0e10cSrcweir     void OListBoxModel::describeFixedProperties( Sequence< Property >& _rProps ) const
445cdf0e10cSrcweir     {
446cdf0e10cSrcweir         BEGIN_DESCRIBE_PROPERTIES( 7, OBoundControlModel )
447cdf0e10cSrcweir             DECL_PROP1(TABINDEX,            sal_Int16,                      BOUND);
448cdf0e10cSrcweir             DECL_PROP2(BOUNDCOLUMN,         sal_Int16,                      BOUND, MAYBEVOID);
449cdf0e10cSrcweir             DECL_PROP1(LISTSOURCETYPE,      ListSourceType,                 BOUND);
450cdf0e10cSrcweir             DECL_PROP1(LISTSOURCE,          StringSequence,                 BOUND);
451cdf0e10cSrcweir             DECL_PROP3(VALUE_SEQ,           StringSequence,                 BOUND, READONLY, TRANSIENT);
452cdf0e10cSrcweir             DECL_PROP1(DEFAULT_SELECT_SEQ,  Sequence<sal_Int16>,            BOUND);
453cdf0e10cSrcweir             DECL_PROP1(STRINGITEMLIST,      Sequence< ::rtl::OUString >,    BOUND);
454cdf0e10cSrcweir         END_DESCRIBE_PROPERTIES();
455cdf0e10cSrcweir     }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir     //------------------------------------------------------------------------------
_propertyChanged(const PropertyChangeEvent & i_rEvent)458cdf0e10cSrcweir     void OListBoxModel::_propertyChanged( const PropertyChangeEvent& i_rEvent ) throw ( RuntimeException )
459cdf0e10cSrcweir     {
460cdf0e10cSrcweir         if ( i_rEvent.PropertyName == PROPERTY_STRINGITEMLIST )
461cdf0e10cSrcweir         {
462cdf0e10cSrcweir             ControlModelLock aLock( *this );
463cdf0e10cSrcweir             // SYNCHRONIZED ----->
464cdf0e10cSrcweir             // our aggregate internally changed its StringItemList property - reflect this in our "overridden"
465cdf0e10cSrcweir             // version of the property
466cdf0e10cSrcweir             setNewStringItemList( i_rEvent.NewValue, aLock );
467cdf0e10cSrcweir             // <----- SYNCHRONIZED
468cdf0e10cSrcweir             return;
469cdf0e10cSrcweir         }
470cdf0e10cSrcweir         OBoundControlModel::_propertyChanged( i_rEvent );
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     //------------------------------------------------------------------------------
describeAggregateProperties(Sequence<Property> & _rAggregateProps) const474cdf0e10cSrcweir     void OListBoxModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         OBoundControlModel::describeAggregateProperties( _rAggregateProps );
477cdf0e10cSrcweir 
478cdf0e10cSrcweir         // superseded properties:
479cdf0e10cSrcweir         RemoveProperty( _rAggregateProps, PROPERTY_STRINGITEMLIST );
480cdf0e10cSrcweir     }
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     //------------------------------------------------------------------------------
getServiceName()483cdf0e10cSrcweir     ::rtl::OUString SAL_CALL OListBoxModel::getServiceName() throw(RuntimeException)
484cdf0e10cSrcweir     {
485cdf0e10cSrcweir         return FRM_COMPONENT_LISTBOX;   // old (non-sun) name for compatibility !
486cdf0e10cSrcweir     }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir     //------------------------------------------------------------------------------
write(const Reference<XObjectOutputStream> & _rxOutStream)489cdf0e10cSrcweir     void SAL_CALL OListBoxModel::write(const Reference<XObjectOutputStream>& _rxOutStream)
490cdf0e10cSrcweir         throw(IOException, RuntimeException)
491cdf0e10cSrcweir     {
492cdf0e10cSrcweir         OBoundControlModel::write(_rxOutStream);
493cdf0e10cSrcweir 
494cdf0e10cSrcweir         // Dummy-Seq, um Kompatible zu bleiben, wenn SelectSeq nicht mehr gespeichert wird
495cdf0e10cSrcweir         Sequence<sal_Int16> aDummySeq;
496cdf0e10cSrcweir 
497cdf0e10cSrcweir         // Version
498cdf0e10cSrcweir         // Version 0x0002: ListSource wird StringSeq
499cdf0e10cSrcweir         _rxOutStream->writeShort(0x0004);
500cdf0e10cSrcweir 
501cdf0e10cSrcweir         // Maskierung fuer any
502cdf0e10cSrcweir         sal_uInt16 nAnyMask = 0;
503cdf0e10cSrcweir         if (m_aBoundColumn.getValueType().getTypeClass() != TypeClass_VOID)
504cdf0e10cSrcweir             nAnyMask |= BOUNDCOLUMN;
505cdf0e10cSrcweir 
506cdf0e10cSrcweir         _rxOutStream << nAnyMask;
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         _rxOutStream << lcl_convertToStringSequence( m_aListSourceValues );
509cdf0e10cSrcweir         _rxOutStream << (sal_Int16)m_eListSourceType;
510cdf0e10cSrcweir         _rxOutStream << aDummySeq;
511cdf0e10cSrcweir         _rxOutStream << m_aDefaultSelectSeq;
512cdf0e10cSrcweir 
513cdf0e10cSrcweir         if ((nAnyMask & BOUNDCOLUMN) == BOUNDCOLUMN)
514cdf0e10cSrcweir         {
515cdf0e10cSrcweir             sal_Int16 nBoundColumn = 0;
516cdf0e10cSrcweir             m_aBoundColumn >>= nBoundColumn;
517cdf0e10cSrcweir             _rxOutStream << nBoundColumn;
518cdf0e10cSrcweir         }
519cdf0e10cSrcweir         writeHelpTextCompatibly(_rxOutStream);
520cdf0e10cSrcweir 
521cdf0e10cSrcweir         // from version 0x0004 : common properties
522cdf0e10cSrcweir         writeCommonProperties(_rxOutStream);
523cdf0e10cSrcweir     }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     //------------------------------------------------------------------------------
read(const Reference<XObjectInputStream> & _rxInStream)526cdf0e10cSrcweir     void SAL_CALL OListBoxModel::read(const Reference<XObjectInputStream>& _rxInStream) throw(IOException, RuntimeException)
527cdf0e10cSrcweir     {
528cdf0e10cSrcweir         // Bei manchen Variblen muessen Abhaengigkeiten beruecksichtigt werden.
529cdf0e10cSrcweir         // Deshalb muessen sie explizit ueber setPropertyValue() gesetzt werden.
530cdf0e10cSrcweir 
531cdf0e10cSrcweir         OBoundControlModel::read(_rxInStream);
532cdf0e10cSrcweir         ControlModelLock aLock( *this );
533cdf0e10cSrcweir 
534cdf0e10cSrcweir         // since we are "overwriting" the StringItemList of our aggregate (means we have
535cdf0e10cSrcweir         // an own place to store the value, instead of relying on our aggregate storing it),
536cdf0e10cSrcweir         // we need to respect what the aggregate just read for the StringItemList property.
537cdf0e10cSrcweir         try
538cdf0e10cSrcweir         {
539cdf0e10cSrcweir             if ( m_xAggregateSet.is() )
540cdf0e10cSrcweir                 setNewStringItemList( m_xAggregateSet->getPropertyValue( PROPERTY_STRINGITEMLIST ), aLock );
541cdf0e10cSrcweir         }
542cdf0e10cSrcweir         catch( const Exception& )
543cdf0e10cSrcweir         {
544cdf0e10cSrcweir     	    OSL_ENSURE( sal_False, "OComboBoxModel::read: caught an exception while examining the aggregate's string item list!" );
545cdf0e10cSrcweir         }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir         // Version
548cdf0e10cSrcweir         sal_uInt16 nVersion = _rxInStream->readShort();
549cdf0e10cSrcweir         DBG_ASSERT(nVersion > 0, "OListBoxModel::read : version 0 ? this should never have been written !");
550cdf0e10cSrcweir 
551cdf0e10cSrcweir         if (nVersion > 0x0004)
552cdf0e10cSrcweir         {
553cdf0e10cSrcweir             DBG_ERROR("OListBoxModel::read : invalid (means unknown) version !");
554cdf0e10cSrcweir             ValueList().swap(m_aListSourceValues);
555cdf0e10cSrcweir             m_aBoundColumn <<= (sal_Int16)0;
556cdf0e10cSrcweir             ValueList().swap(m_aBoundValues);
557cdf0e10cSrcweir             m_eListSourceType = ListSourceType_VALUELIST;
558cdf0e10cSrcweir             m_aDefaultSelectSeq.realloc(0);
559cdf0e10cSrcweir             defaultCommonProperties();
560cdf0e10cSrcweir             return;
561cdf0e10cSrcweir         }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         // Maskierung fuer any
564cdf0e10cSrcweir         sal_uInt16 nAnyMask;
565cdf0e10cSrcweir         _rxInStream >> nAnyMask;
566cdf0e10cSrcweir 
567cdf0e10cSrcweir         // ListSourceSeq
568cdf0e10cSrcweir         StringSequence aListSourceSeq;
569cdf0e10cSrcweir         if (nVersion == 0x0001)
570cdf0e10cSrcweir         {
571cdf0e10cSrcweir             // ListSourceSeq aus String zusammenstellen;
572cdf0e10cSrcweir             ::rtl::OUString sListSource;
573cdf0e10cSrcweir             _rxInStream >> sListSource;
574cdf0e10cSrcweir 
575cdf0e10cSrcweir             sal_Int32 nTokens = 1;
576cdf0e10cSrcweir             const sal_Unicode* pStr = sListSource.getStr();
577cdf0e10cSrcweir             while ( *pStr )
578cdf0e10cSrcweir             {
579cdf0e10cSrcweir                 if ( *pStr == ';' )
580cdf0e10cSrcweir                     nTokens++;
581cdf0e10cSrcweir                 pStr++;
582cdf0e10cSrcweir             }
583cdf0e10cSrcweir             aListSourceSeq.realloc( nTokens );
584cdf0e10cSrcweir             for (sal_uInt16 i=0; i<nTokens; ++i)
585cdf0e10cSrcweir             {
586cdf0e10cSrcweir                 sal_Int32 nTmp = 0;
587cdf0e10cSrcweir                 aListSourceSeq.getArray()[i] = sListSource.getToken(i,';',nTmp);
588cdf0e10cSrcweir             }
589cdf0e10cSrcweir         }
590cdf0e10cSrcweir         else
591cdf0e10cSrcweir             _rxInStream >> aListSourceSeq;
592cdf0e10cSrcweir 
593cdf0e10cSrcweir         sal_Int16 nListSourceType;
594cdf0e10cSrcweir         _rxInStream >> nListSourceType;
595cdf0e10cSrcweir         m_eListSourceType = (ListSourceType)nListSourceType;
596cdf0e10cSrcweir         Any aListSourceSeqAny;
597cdf0e10cSrcweir         aListSourceSeqAny <<= aListSourceSeq;
598cdf0e10cSrcweir 
599cdf0e10cSrcweir         setFastPropertyValue(PROPERTY_ID_LISTSOURCE, aListSourceSeqAny );
600cdf0e10cSrcweir 
601cdf0e10cSrcweir         // Dummy-Seq, um Kompatible zu bleiben, wenn SelectSeq nicht mehr gespeichert wird
602cdf0e10cSrcweir         Sequence<sal_Int16> aDummySeq;
603cdf0e10cSrcweir         _rxInStream >> aDummySeq;
604cdf0e10cSrcweir 
605cdf0e10cSrcweir         // DefaultSelectSeq
606cdf0e10cSrcweir         Sequence<sal_Int16> aDefaultSelectSeq;
607cdf0e10cSrcweir         _rxInStream >> aDefaultSelectSeq;
608cdf0e10cSrcweir         Any aDefaultSelectSeqAny;
609cdf0e10cSrcweir         aDefaultSelectSeqAny <<= aDefaultSelectSeq;
610cdf0e10cSrcweir         setFastPropertyValue(PROPERTY_ID_DEFAULT_SELECT_SEQ, aDefaultSelectSeqAny);
611cdf0e10cSrcweir 
612cdf0e10cSrcweir         // BoundColumn
613cdf0e10cSrcweir         if ((nAnyMask & BOUNDCOLUMN) == BOUNDCOLUMN)
614cdf0e10cSrcweir         {
615cdf0e10cSrcweir             sal_Int16 nValue;
616cdf0e10cSrcweir             _rxInStream >> nValue;
617cdf0e10cSrcweir             m_aBoundColumn <<= nValue;
618cdf0e10cSrcweir         }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir         if (nVersion > 2)
621cdf0e10cSrcweir             readHelpTextCompatibly(_rxInStream);
622cdf0e10cSrcweir 
623cdf0e10cSrcweir         // if our string list is not filled from the value list, we must empty it
624cdf0e10cSrcweir         // this can be the case when somebody saves in alive mode
625cdf0e10cSrcweir         if  (   ( m_eListSourceType != ListSourceType_VALUELIST )
626cdf0e10cSrcweir             &&  !hasExternalListSource()
627cdf0e10cSrcweir             )
628cdf0e10cSrcweir         {
629cdf0e10cSrcweir             setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( StringSequence() ) );
630cdf0e10cSrcweir         }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir         if (nVersion > 3)
633cdf0e10cSrcweir             readCommonProperties(_rxInStream);
634cdf0e10cSrcweir 
635cdf0e10cSrcweir         // Nach dem Lesen die Defaultwerte anzeigen
636cdf0e10cSrcweir         if ( getControlSource().getLength() )
637cdf0e10cSrcweir             // (not if we don't have a control source - the "State" property acts like it is persistent, then
638cdf0e10cSrcweir             resetNoBroadcast();
639cdf0e10cSrcweir     }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir     //------------------------------------------------------------------------------
loadData(bool _bForce)642cdf0e10cSrcweir     void OListBoxModel::loadData( bool _bForce )
643cdf0e10cSrcweir     {
644cdf0e10cSrcweir         RTL_LOGFILE_CONTEXT( aLogContext, "OListBoxModel::loadData" );
645cdf0e10cSrcweir         DBG_ASSERT( m_eListSourceType != ListSourceType_VALUELIST, "OListBoxModel::loadData: cannot load value list from DB!" );
646cdf0e10cSrcweir         DBG_ASSERT( !hasExternalListSource(), "OListBoxModel::loadData: cannot load from DB when I have an external list source!" );
647cdf0e10cSrcweir 
648cdf0e10cSrcweir         const sal_Int16 nNULLPosBackup( m_nNULLPos );
649cdf0e10cSrcweir         const sal_Int32 nBoundColumnTypeBackup( m_nBoundColumnType );
650cdf0e10cSrcweir         m_nNULLPos = -1;
651cdf0e10cSrcweir         m_nBoundColumnType = DataType::SQLNULL;
652cdf0e10cSrcweir 
653cdf0e10cSrcweir         // pre-requisites:
654cdf0e10cSrcweir         // PRE1: connection
655cdf0e10cSrcweir         Reference< XConnection > xConnection;
656cdf0e10cSrcweir         // is the active connection of our form
657cdf0e10cSrcweir         Reference< XPropertySet > xFormProps( m_xCursor, UNO_QUERY );
658cdf0e10cSrcweir         if ( xFormProps.is() )
659cdf0e10cSrcweir             xFormProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         // PRE2: list source
662cdf0e10cSrcweir         ::rtl::OUString sListSource;
663cdf0e10cSrcweir         // if our list source type is no value list, we need to concatenate
664cdf0e10cSrcweir         // the single list source elements
665cdf0e10cSrcweir         ::std::for_each(
666cdf0e10cSrcweir             m_aListSourceValues.begin(),
667cdf0e10cSrcweir             m_aListSourceValues.end(),
668cdf0e10cSrcweir             AppendRowSetValueString( sListSource )
669cdf0e10cSrcweir         );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir         // outta here if we don't have all pre-requisites
672cdf0e10cSrcweir         if ( !xConnection.is() || !sListSource.getLength() )
673cdf0e10cSrcweir         {
674cdf0e10cSrcweir             ValueList().swap(m_aBoundValues);
675cdf0e10cSrcweir             return;
676cdf0e10cSrcweir         }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir         ::boost::optional< sal_Int16 > aBoundColumn;
679cdf0e10cSrcweir         if ( m_aBoundColumn.getValueType().getTypeClass() == TypeClass_SHORT )
680cdf0e10cSrcweir         {
681cdf0e10cSrcweir             sal_Int16 nBoundColumn( 0 );
682cdf0e10cSrcweir             m_aBoundColumn >>= nBoundColumn;
683cdf0e10cSrcweir             aBoundColumn.reset( nBoundColumn );
684cdf0e10cSrcweir         }
685cdf0e10cSrcweir 
686cdf0e10cSrcweir         ::utl::SharedUNOComponent< XResultSet > xListCursor;
687cdf0e10cSrcweir         try
688cdf0e10cSrcweir         {
689cdf0e10cSrcweir             m_aListRowSet.setConnection( xConnection );
690cdf0e10cSrcweir 
691cdf0e10cSrcweir             sal_Bool bExecute = sal_False;
692cdf0e10cSrcweir             switch (m_eListSourceType)
693cdf0e10cSrcweir             {
694cdf0e10cSrcweir             case ListSourceType_TABLEFIELDS:
695cdf0e10cSrcweir                 // don't work with a statement here, the fields will be collected below
696cdf0e10cSrcweir                 break;
697cdf0e10cSrcweir 
698cdf0e10cSrcweir             case ListSourceType_TABLE:
699cdf0e10cSrcweir                 {
700cdf0e10cSrcweir                     Reference<XNameAccess> xFieldsByName = getTableFields(xConnection, sListSource);
701cdf0e10cSrcweir                     Reference<XIndexAccess> xFieldsByIndex(xFieldsByName, UNO_QUERY);
702cdf0e10cSrcweir 
703cdf0e10cSrcweir                     // do we have a bound column if yes we have to select it
704cdf0e10cSrcweir                     // and the displayed column is the first column othwhise we act as a combobox
705cdf0e10cSrcweir                     ::rtl::OUString aFieldName;
706cdf0e10cSrcweir                     ::rtl::OUString aBoundFieldName;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir                     if ( !!aBoundColumn && ( *aBoundColumn >= 0 ) && xFieldsByIndex.is() )
709cdf0e10cSrcweir                     {
710cdf0e10cSrcweir                         if ( *aBoundColumn >= xFieldsByIndex->getCount() )
711cdf0e10cSrcweir                             break;
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 						Reference<XPropertySet> xFieldAsSet(xFieldsByIndex->getByIndex( *aBoundColumn ),UNO_QUERY);
714cdf0e10cSrcweir                         xFieldAsSet->getPropertyValue(PROPERTY_NAME) >>= aBoundFieldName;
715cdf0e10cSrcweir                         aBoundColumn.reset( 1 );
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 						xFieldAsSet.set(xFieldsByIndex->getByIndex(0),UNO_QUERY);
718cdf0e10cSrcweir                         xFieldAsSet->getPropertyValue(PROPERTY_NAME) >>= aFieldName;
719cdf0e10cSrcweir                     }
720cdf0e10cSrcweir                     else if (xFieldsByName.is())
721cdf0e10cSrcweir                     {
722cdf0e10cSrcweir                         if ( xFieldsByName->hasByName( getControlSource() ) )
723cdf0e10cSrcweir                             aFieldName = getControlSource();
724cdf0e10cSrcweir                         else
725cdf0e10cSrcweir                         {
726cdf0e10cSrcweir                             // otherwise look for the alias
727cdf0e10cSrcweir                             Reference< XColumnsSupplier > xSupplyFields;
728cdf0e10cSrcweir                             xFormProps->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupplyFields;
729cdf0e10cSrcweir 
730cdf0e10cSrcweir                             // search the field
731cdf0e10cSrcweir                             DBG_ASSERT(xSupplyFields.is(), "OListBoxModel::loadData : invalid query composer !");
732cdf0e10cSrcweir 
733cdf0e10cSrcweir                             Reference<XNameAccess> xFieldNames = xSupplyFields->getColumns();
734cdf0e10cSrcweir                             if ( xFieldNames->hasByName( getControlSource() ) )
735cdf0e10cSrcweir                             {
736cdf0e10cSrcweir                                 Reference<XPropertySet> xComposerFieldAsSet;
737cdf0e10cSrcweir                                 xFieldNames->getByName( getControlSource() ) >>= xComposerFieldAsSet;
738cdf0e10cSrcweir                                 if (hasProperty(PROPERTY_FIELDSOURCE, xComposerFieldAsSet))
739cdf0e10cSrcweir                                     xComposerFieldAsSet->getPropertyValue(PROPERTY_FIELDSOURCE) >>= aFieldName;
740cdf0e10cSrcweir                             }
741cdf0e10cSrcweir                         }
742cdf0e10cSrcweir                     }
743cdf0e10cSrcweir                     if (!aFieldName.getLength())
744cdf0e10cSrcweir                         break;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir                     Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
747cdf0e10cSrcweir                     ::rtl::OUString aQuote = xMeta->getIdentifierQuoteString();
748cdf0e10cSrcweir                     ::rtl::OUString aStatement = ::rtl::OUString::createFromAscii("SELECT ");
749cdf0e10cSrcweir                     if (!aBoundFieldName.getLength())   // act like a combobox
750cdf0e10cSrcweir                         aStatement += ::rtl::OUString::createFromAscii("DISTINCT ");
751cdf0e10cSrcweir 
752cdf0e10cSrcweir                     aStatement += quoteName(aQuote,aFieldName);
753cdf0e10cSrcweir                     if (aBoundFieldName.getLength())
754cdf0e10cSrcweir                     {
755cdf0e10cSrcweir                         aStatement += ::rtl::OUString::createFromAscii(", ");
756cdf0e10cSrcweir                         aStatement += quoteName(aQuote, aBoundFieldName);
757cdf0e10cSrcweir                     }
758cdf0e10cSrcweir                     aStatement += ::rtl::OUString::createFromAscii(" FROM ");
759cdf0e10cSrcweir 
760cdf0e10cSrcweir                     ::rtl::OUString sCatalog, sSchema, sTable;
761cdf0e10cSrcweir 	                qualifiedNameComponents( xMeta, sListSource, sCatalog, sSchema, sTable, eInDataManipulation );
762cdf0e10cSrcweir                     aStatement += composeTableNameForSelect( xConnection, sCatalog, sSchema, sTable );
763cdf0e10cSrcweir 
764cdf0e10cSrcweir                     m_aListRowSet.setEscapeProcessing( sal_False );
765cdf0e10cSrcweir                     m_aListRowSet.setCommand( aStatement );
766cdf0e10cSrcweir                     bExecute = sal_True;
767cdf0e10cSrcweir                 }
768cdf0e10cSrcweir                 break;
769cdf0e10cSrcweir 
770cdf0e10cSrcweir             case ListSourceType_QUERY:
771cdf0e10cSrcweir                 m_aListRowSet.setCommandFromQuery( sListSource );
772cdf0e10cSrcweir                 bExecute = sal_True;
773cdf0e10cSrcweir                 break;
774cdf0e10cSrcweir 
775cdf0e10cSrcweir             default:
776cdf0e10cSrcweir                 m_aListRowSet.setEscapeProcessing( ListSourceType_SQLPASSTHROUGH != m_eListSourceType );
777cdf0e10cSrcweir                 m_aListRowSet.setCommand( sListSource );
778cdf0e10cSrcweir                 bExecute = sal_True;
779cdf0e10cSrcweir                 break;
780cdf0e10cSrcweir             }
781cdf0e10cSrcweir 
782cdf0e10cSrcweir             if (bExecute)
783cdf0e10cSrcweir             {
784cdf0e10cSrcweir                 if ( !_bForce && !m_aListRowSet.isDirty() )
785cdf0e10cSrcweir                 {
786cdf0e10cSrcweir                     // if none of the settings of the row set changed, compared to the last
787cdf0e10cSrcweir                     // invocation of loadData, then don't re-fill the list. Instead, assume
788cdf0e10cSrcweir                     // the list entries are the same.
789cdf0e10cSrcweir                     m_nNULLPos = nNULLPosBackup;
790cdf0e10cSrcweir                     m_nBoundColumnType = nBoundColumnTypeBackup;
791cdf0e10cSrcweir                     return;
792cdf0e10cSrcweir                 }
793cdf0e10cSrcweir                 xListCursor.reset( m_aListRowSet.execute() );
794cdf0e10cSrcweir             }
795cdf0e10cSrcweir         }
796cdf0e10cSrcweir         catch(SQLException& eSQL)
797cdf0e10cSrcweir         {
798cdf0e10cSrcweir             onError(eSQL, FRM_RES_STRING(RID_BASELISTBOX_ERROR_FILLLIST));
799cdf0e10cSrcweir             return;
800cdf0e10cSrcweir         }
801cdf0e10cSrcweir         catch(const Exception& eUnknown)
802cdf0e10cSrcweir         {
803cdf0e10cSrcweir             (void)eUnknown;
804cdf0e10cSrcweir             return;
805cdf0e10cSrcweir         }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir         // Anzeige- und Werteliste fuellen
808cdf0e10cSrcweir         ValueList aDisplayList, aValueList;
809cdf0e10cSrcweir         sal_Bool bUseNULL = hasField() && !isRequired();
810cdf0e10cSrcweir 
811cdf0e10cSrcweir         try
812cdf0e10cSrcweir         {
813cdf0e10cSrcweir             OSL_ENSURE( xListCursor.is() || ( ListSourceType_TABLEFIELDS == m_eListSourceType ),
814cdf0e10cSrcweir                 "OListBoxModel::loadData: logic error!" );
815cdf0e10cSrcweir             if ( !xListCursor.is() && ( ListSourceType_TABLEFIELDS != m_eListSourceType ) )
816cdf0e10cSrcweir                 return;
817cdf0e10cSrcweir 
818cdf0e10cSrcweir             switch (m_eListSourceType)
819cdf0e10cSrcweir             {
820cdf0e10cSrcweir             case ListSourceType_SQL:
821cdf0e10cSrcweir             case ListSourceType_SQLPASSTHROUGH:
822cdf0e10cSrcweir             case ListSourceType_TABLE:
823cdf0e10cSrcweir             case ListSourceType_QUERY:
824cdf0e10cSrcweir                 {
825cdf0e10cSrcweir                     // Feld der 1. Column des ResultSets holen
826cdf0e10cSrcweir                     Reference<XColumnsSupplier> xSupplyCols(xListCursor, UNO_QUERY);
827cdf0e10cSrcweir                     DBG_ASSERT(xSupplyCols.is(), "OListBoxModel::loadData : cursor supports the row set service but is no column supplier?!");
828cdf0e10cSrcweir                     Reference<XIndexAccess> xColumns;
829cdf0e10cSrcweir                     if (xSupplyCols.is())
830cdf0e10cSrcweir                     {
831cdf0e10cSrcweir                         xColumns = Reference<XIndexAccess>(xSupplyCols->getColumns(), UNO_QUERY);
832cdf0e10cSrcweir                         DBG_ASSERT(xColumns.is(), "OListBoxModel::loadData : no columns supplied by the row set !");
833cdf0e10cSrcweir                     }
834cdf0e10cSrcweir 
835cdf0e10cSrcweir                     Reference< XPropertySet > xDataField;
836cdf0e10cSrcweir                     if ( xColumns.is() )
837cdf0e10cSrcweir                         xColumns->getByIndex(0) >>= xDataField;
838cdf0e10cSrcweir                     if ( !xDataField.is() )
839cdf0e10cSrcweir                         return;
840cdf0e10cSrcweir 
841cdf0e10cSrcweir                     ::dbtools::FormattedColumnValue aValueFormatter( getContext(), m_xCursor, xDataField );
842cdf0e10cSrcweir 
843cdf0e10cSrcweir                     // Feld der BoundColumn des ResultSets holen
844cdf0e10cSrcweir                     m_nBoundColumnType = DataType::SQLNULL;
845cdf0e10cSrcweir                     if ( !!aBoundColumn && ( *aBoundColumn >= 0 ) && m_xColumn.is() )
846cdf0e10cSrcweir                     {   // don't look for a bound column if we're not connected to a field
847cdf0e10cSrcweir                         try
848cdf0e10cSrcweir                         {
849cdf0e10cSrcweir                             Reference< XPropertySet > xBoundField( xColumns->getByIndex( *aBoundColumn ), UNO_QUERY_THROW );
850cdf0e10cSrcweir                             OSL_VERIFY( xBoundField->getPropertyValue( ::rtl::OUString::createFromAscii( "Type" ) ) >>= m_nBoundColumnType );
851cdf0e10cSrcweir                         }
852cdf0e10cSrcweir                         catch( const Exception& )
853cdf0e10cSrcweir                         {
854cdf0e10cSrcweir                             DBG_UNHANDLED_EXCEPTION();
855cdf0e10cSrcweir                         }
856cdf0e10cSrcweir                     }
857cdf0e10cSrcweir 
858cdf0e10cSrcweir                     //  Ist die LB an ein Feld gebunden und sind Leereintraege zulaessig
859cdf0e10cSrcweir                     //  dann wird die Position fuer einen Leereintrag gemerkt
860cdf0e10cSrcweir 
861cdf0e10cSrcweir                     RTL_LOGFILE_CONTEXT( aLogContext, "OListBoxModel::loadData: string collection" );
862cdf0e10cSrcweir                     ::rtl::OUString aStr;
863cdf0e10cSrcweir                     sal_Int16 entryPos = 0;
864cdf0e10cSrcweir                     ORowSetValue aBoundValue;
865cdf0e10cSrcweir                     Reference< XRow > xCursorRow( xListCursor, UNO_QUERY_THROW );
866cdf0e10cSrcweir                     while ( xListCursor->next() && ( entryPos++ < SHRT_MAX ) ) // SHRT_MAX is the maximum number of entries
867cdf0e10cSrcweir                     {
868cdf0e10cSrcweir                         aStr = aValueFormatter.getFormattedValue();
869cdf0e10cSrcweir                         aDisplayList.push_back( aStr );
870cdf0e10cSrcweir 
871cdf0e10cSrcweir                         if ( impl_hasBoundComponent() )
872cdf0e10cSrcweir                         {
873cdf0e10cSrcweir                             aBoundValue.fill( *aBoundColumn + 1, m_nBoundColumnType, xCursorRow );
874cdf0e10cSrcweir                             aValueList.push_back( aBoundValue );
875cdf0e10cSrcweir                         }
876cdf0e10cSrcweir 
877cdf0e10cSrcweir                         if ( bUseNULL && ( m_nNULLPos == -1 ) && !aStr.getLength() )
878cdf0e10cSrcweir                             m_nNULLPos = sal_Int16( aDisplayList.size() - 1 );
879cdf0e10cSrcweir                     }
880cdf0e10cSrcweir                 }
881cdf0e10cSrcweir                 break;
882cdf0e10cSrcweir 
883cdf0e10cSrcweir             case ListSourceType_TABLEFIELDS:
884cdf0e10cSrcweir                 {
885cdf0e10cSrcweir                     Reference<XNameAccess> xFieldNames = getTableFields(xConnection, sListSource);
886cdf0e10cSrcweir                     if (xFieldNames.is())
887cdf0e10cSrcweir                     {
888cdf0e10cSrcweir                         StringSequence seqNames = xFieldNames->getElementNames();
889cdf0e10cSrcweir                         ::std::copy(
890cdf0e10cSrcweir                             seqNames.getConstArray(),
891cdf0e10cSrcweir                             seqNames.getConstArray() + seqNames.getLength(),
892cdf0e10cSrcweir                             ::std::insert_iterator< ValueList >( aDisplayList, aDisplayList.end() )
893cdf0e10cSrcweir                         );
894cdf0e10cSrcweir                     }
895cdf0e10cSrcweir                 }
896cdf0e10cSrcweir                 break;
897cdf0e10cSrcweir                 default:
898cdf0e10cSrcweir                     OSL_ENSURE( false, "OListBoxModel::loadData: unreachable!" );
899cdf0e10cSrcweir                     break;
900cdf0e10cSrcweir             }
901cdf0e10cSrcweir         }
902cdf0e10cSrcweir         catch(SQLException& eSQL)
903cdf0e10cSrcweir         {
904cdf0e10cSrcweir             onError(eSQL, FRM_RES_STRING(RID_BASELISTBOX_ERROR_FILLLIST));
905cdf0e10cSrcweir             return;
906cdf0e10cSrcweir         }
907cdf0e10cSrcweir         catch( const Exception& )
908cdf0e10cSrcweir         {
909cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
910cdf0e10cSrcweir             return;
911cdf0e10cSrcweir         }
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 
914cdf0e10cSrcweir         // Value-Sequence erzeugen
915cdf0e10cSrcweir         // NULL eintrag hinzufuegen
916cdf0e10cSrcweir         if (bUseNULL && m_nNULLPos == -1)
917cdf0e10cSrcweir         {
918cdf0e10cSrcweir             if ( impl_hasBoundComponent() )
919cdf0e10cSrcweir                 aValueList.insert( aValueList.begin(), ORowSetValue() );
920cdf0e10cSrcweir 
921cdf0e10cSrcweir             aDisplayList.insert( aDisplayList.begin(), ORowSetValue( ::rtl::OUString() ) );
922cdf0e10cSrcweir             m_nNULLPos = 0;
923cdf0e10cSrcweir         }
924cdf0e10cSrcweir 
925cdf0e10cSrcweir         m_aBoundValues = aValueList;
926cdf0e10cSrcweir 
927cdf0e10cSrcweir         setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( lcl_convertToStringSequence( aDisplayList ) ) );
928cdf0e10cSrcweir     }
929cdf0e10cSrcweir 
930cdf0e10cSrcweir     //------------------------------------------------------------------------------
onConnectedDbColumn(const Reference<XInterface> &)931cdf0e10cSrcweir     void OListBoxModel::onConnectedDbColumn( const Reference< XInterface >& /*_rxForm*/ )
932cdf0e10cSrcweir     {
933cdf0e10cSrcweir         // list boxes which are bound to a db column don't have multi selection
934cdf0e10cSrcweir         // - this would be unable to reflect in the db column
935cdf0e10cSrcweir         if ( hasField() )
936cdf0e10cSrcweir         {
937cdf0e10cSrcweir             setFastPropertyValue( PROPERTY_ID_MULTISELECTION, ::cppu::bool2any( ( sal_False ) ) );
938cdf0e10cSrcweir         }
939cdf0e10cSrcweir 
940cdf0e10cSrcweir         if ( !hasExternalListSource() )
941cdf0e10cSrcweir             impl_refreshDbEntryList( false );
942cdf0e10cSrcweir     }
943cdf0e10cSrcweir 
944cdf0e10cSrcweir     //------------------------------------------------------------------------------
onDisconnectedDbColumn()945cdf0e10cSrcweir     void OListBoxModel::onDisconnectedDbColumn()
946cdf0e10cSrcweir     {
947cdf0e10cSrcweir         if ( m_eListSourceType != ListSourceType_VALUELIST )
948cdf0e10cSrcweir         {
949cdf0e10cSrcweir             ValueList().swap(m_aBoundValues);
950cdf0e10cSrcweir             m_nNULLPos = -1;
951cdf0e10cSrcweir             m_nBoundColumnType = DataType::SQLNULL;
952cdf0e10cSrcweir 
953cdf0e10cSrcweir             if ( !hasExternalListSource() )
954cdf0e10cSrcweir                 setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( StringSequence() ) );
955cdf0e10cSrcweir 
956cdf0e10cSrcweir             m_aListRowSet.dispose();
957cdf0e10cSrcweir         }
958cdf0e10cSrcweir     }
959cdf0e10cSrcweir 
960cdf0e10cSrcweir     //------------------------------------------------------------------------------
impl_getValues() const961cdf0e10cSrcweir     ValueList OListBoxModel::impl_getValues() const
962cdf0e10cSrcweir     {
963cdf0e10cSrcweir         if ( !m_aBoundValues.empty() )
964cdf0e10cSrcweir             return m_aBoundValues;
965cdf0e10cSrcweir 
966cdf0e10cSrcweir         Sequence< ::rtl::OUString > aStringItems( getStringItemList() );
967cdf0e10cSrcweir         ValueList aValues( aStringItems.getLength() );
968cdf0e10cSrcweir         ::std::copy(
969cdf0e10cSrcweir             aStringItems.getConstArray(),
970cdf0e10cSrcweir             aStringItems.getConstArray() + aStringItems.getLength(),
971cdf0e10cSrcweir             aValues.begin()
972cdf0e10cSrcweir         );
973cdf0e10cSrcweir 
974cdf0e10cSrcweir         return aValues;
975cdf0e10cSrcweir     }
976cdf0e10cSrcweir     //------------------------------------------------------------------------------
getFirstSelectedValue() const977cdf0e10cSrcweir     ORowSetValue OListBoxModel::getFirstSelectedValue() const
978cdf0e10cSrcweir     {
979cdf0e10cSrcweir         static const ORowSetValue s_aEmptyVaue;
980cdf0e10cSrcweir 
981cdf0e10cSrcweir         DBG_ASSERT( m_xAggregateFastSet.is(), "OListBoxModel::getFirstSelectedValue: invalid aggregate!" );
982cdf0e10cSrcweir         if ( !m_xAggregateFastSet.is() )
983cdf0e10cSrcweir             return s_aEmptyVaue;
984cdf0e10cSrcweir 
985cdf0e10cSrcweir         Sequence< sal_Int16 > aSelectedIndices;
986cdf0e10cSrcweir         OSL_VERIFY( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) >>= aSelectedIndices );
987cdf0e10cSrcweir         if ( !aSelectedIndices.getLength() )
988cdf0e10cSrcweir             // nothing selected at all
989cdf0e10cSrcweir             return s_aEmptyVaue;
990cdf0e10cSrcweir 
991cdf0e10cSrcweir         if ( ( m_nNULLPos != -1 ) && ( aSelectedIndices[0] == m_nNULLPos ) )
992cdf0e10cSrcweir             // the dedicated "NULL" entry is selected
993cdf0e10cSrcweir             return s_aEmptyVaue;
994cdf0e10cSrcweir 
995cdf0e10cSrcweir         ValueList aValues( impl_getValues() );
996cdf0e10cSrcweir 
997cdf0e10cSrcweir         size_t selectedValue = aSelectedIndices[0];
998cdf0e10cSrcweir         if ( selectedValue >= aValues.size() )
999cdf0e10cSrcweir         {
1000cdf0e10cSrcweir             OSL_ENSURE( false, "OListBoxModel::getFirstSelectedValue: inconsistent selection/valuelist!" );
1001cdf0e10cSrcweir             return s_aEmptyVaue;
1002cdf0e10cSrcweir         }
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir         return aValues[ selectedValue ];
1005cdf0e10cSrcweir     }
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir     //------------------------------------------------------------------------------
commitControlValueToDbColumn(bool)1008cdf0e10cSrcweir     sal_Bool OListBoxModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
1009cdf0e10cSrcweir     {
1010cdf0e10cSrcweir         // current selektion list
1011cdf0e10cSrcweir         const ORowSetValue aCurrentValue( getFirstSelectedValue() );
1012cdf0e10cSrcweir         if ( aCurrentValue != m_aSaveValue )
1013cdf0e10cSrcweir         {
1014cdf0e10cSrcweir             if ( aCurrentValue.isNull() )
1015cdf0e10cSrcweir                 m_xColumnUpdate->updateNull();
1016cdf0e10cSrcweir             else
1017cdf0e10cSrcweir             {
1018cdf0e10cSrcweir                 try
1019cdf0e10cSrcweir                 {
1020cdf0e10cSrcweir                     m_xColumnUpdate->updateObject( aCurrentValue.makeAny() );
1021cdf0e10cSrcweir                 }
1022cdf0e10cSrcweir                 catch ( const Exception& )
1023cdf0e10cSrcweir                 {
1024cdf0e10cSrcweir                     return sal_False;
1025cdf0e10cSrcweir                 }
1026cdf0e10cSrcweir             }
1027cdf0e10cSrcweir             m_aSaveValue = aCurrentValue;
1028cdf0e10cSrcweir         }
1029cdf0e10cSrcweir         return sal_True;
1030cdf0e10cSrcweir     }
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir     // XPropertiesChangeListener
1033cdf0e10cSrcweir     //------------------------------------------------------------------------------
translateDbColumnToControlValue()1034cdf0e10cSrcweir     Any OListBoxModel::translateDbColumnToControlValue()
1035cdf0e10cSrcweir     {
1036cdf0e10cSrcweir         Reference< XPropertySet > xBoundField( getField() );
1037cdf0e10cSrcweir         if ( !xBoundField.is() )
1038cdf0e10cSrcweir         {
1039cdf0e10cSrcweir             OSL_ENSURE( false, "OListBoxModel::translateDbColumnToControlValue: no field? How could that happen?!" );
1040cdf0e10cSrcweir             return Any();
1041cdf0e10cSrcweir         }
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir         Sequence< sal_Int16 > aSelectionIndicies;
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir         ORowSetValue aCurrentValue;
1046cdf0e10cSrcweir         aCurrentValue.fill( impl_hasBoundComponent() ? m_nBoundColumnType : getFieldType(), m_xColumn );
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir         // reset selection for NULL values
1049cdf0e10cSrcweir         if ( aCurrentValue.isNull() )
1050cdf0e10cSrcweir         {
1051cdf0e10cSrcweir             if ( m_nNULLPos != -1 )
1052cdf0e10cSrcweir             {
1053cdf0e10cSrcweir                 aSelectionIndicies.realloc(1);
1054cdf0e10cSrcweir                 aSelectionIndicies[0] = m_nNULLPos;
1055cdf0e10cSrcweir             }
1056cdf0e10cSrcweir         }
1057cdf0e10cSrcweir         else
1058cdf0e10cSrcweir         {
1059cdf0e10cSrcweir             ValueList aValues( impl_getValues() );
1060cdf0e10cSrcweir             ValueList::const_iterator curValuePos = ::std::find( aValues.begin(), aValues.end(), aCurrentValue );
1061cdf0e10cSrcweir             if ( curValuePos != aValues.end() )
1062cdf0e10cSrcweir             {
1063cdf0e10cSrcweir                 aSelectionIndicies.realloc( 1 );
1064cdf0e10cSrcweir                 aSelectionIndicies[0] = curValuePos - aValues.begin();
1065cdf0e10cSrcweir             }
1066cdf0e10cSrcweir         }
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir         m_aSaveValue = aCurrentValue;
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir         return makeAny( aSelectionIndicies );
1071cdf0e10cSrcweir     }
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir     // XReset
1074cdf0e10cSrcweir     //------------------------------------------------------------------------------
getDefaultForReset() const1075cdf0e10cSrcweir     Any OListBoxModel::getDefaultForReset() const
1076cdf0e10cSrcweir     {
1077cdf0e10cSrcweir         Any aValue;
1078cdf0e10cSrcweir         if (m_aDefaultSelectSeq.getLength())
1079cdf0e10cSrcweir             aValue <<= m_aDefaultSelectSeq;
1080cdf0e10cSrcweir         else if (m_nNULLPos != -1)  // gebundene Listbox
1081cdf0e10cSrcweir         {
1082cdf0e10cSrcweir             Sequence<sal_Int16> aSeq(1);
1083cdf0e10cSrcweir             aSeq.getArray()[0] = m_nNULLPos;
1084cdf0e10cSrcweir             aValue <<= aSeq;
1085cdf0e10cSrcweir         }
1086cdf0e10cSrcweir         else
1087cdf0e10cSrcweir         {
1088cdf0e10cSrcweir             Sequence<sal_Int16> aSeq;
1089cdf0e10cSrcweir             aValue <<= aSeq;
1090cdf0e10cSrcweir         }
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir         return aValue;
1093cdf0e10cSrcweir     }
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir     //--------------------------------------------------------------------
resetNoBroadcast()1096cdf0e10cSrcweir     void OListBoxModel::resetNoBroadcast()
1097cdf0e10cSrcweir     {
1098cdf0e10cSrcweir         OBoundControlModel::resetNoBroadcast();
1099cdf0e10cSrcweir         m_aSaveValue.setNull();
1100cdf0e10cSrcweir     }
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir     //--------------------------------------------------------------------
disposing(const EventObject & _rSource)1103cdf0e10cSrcweir     void SAL_CALL OListBoxModel::disposing( const EventObject& _rSource ) throw ( RuntimeException )
1104cdf0e10cSrcweir     {
1105cdf0e10cSrcweir         if ( !OEntryListHelper::handleDisposing( _rSource ) )
1106cdf0e10cSrcweir             OBoundControlModel::disposing( _rSource );
1107cdf0e10cSrcweir     }
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir     //--------------------------------------------------------------------
1110cdf0e10cSrcweir     namespace
1111cdf0e10cSrcweir     {
1112cdf0e10cSrcweir         /** type how we should transfer our selection to external value bindings
1113cdf0e10cSrcweir         */
1114cdf0e10cSrcweir         enum ExchangeType
1115cdf0e10cSrcweir         {
1116cdf0e10cSrcweir             eIndexList,     /// as list of indexes of selected entries
1117cdf0e10cSrcweir             eIndex,         /// as index of the selected entry
1118cdf0e10cSrcweir             eEntryList,     /// as list of string representations of selected entries
1119cdf0e10cSrcweir             eEntry          /// as string representation of the selected entry
1120cdf0e10cSrcweir         };
1121cdf0e10cSrcweir 
1122cdf0e10cSrcweir         //--------------------------------------------------------------------
lcl_getCurrentExchangeType(const Type & _rExchangeType)1123cdf0e10cSrcweir         ExchangeType lcl_getCurrentExchangeType( const Type& _rExchangeType )
1124cdf0e10cSrcweir         {
1125cdf0e10cSrcweir             switch ( _rExchangeType.getTypeClass() )
1126cdf0e10cSrcweir             {
1127cdf0e10cSrcweir             case TypeClass_STRING:
1128cdf0e10cSrcweir                 return eEntry;
1129cdf0e10cSrcweir             case TypeClass_LONG:
1130cdf0e10cSrcweir                 return eIndex;
1131cdf0e10cSrcweir             case TypeClass_SEQUENCE:
1132cdf0e10cSrcweir             {
1133cdf0e10cSrcweir                 Type aElementType = ::comphelper::getSequenceElementType( _rExchangeType );
1134cdf0e10cSrcweir                 switch ( aElementType.getTypeClass() )
1135cdf0e10cSrcweir                 {
1136cdf0e10cSrcweir                 case TypeClass_STRING:
1137cdf0e10cSrcweir                     return eEntryList;
1138cdf0e10cSrcweir                 case TypeClass_LONG:
1139cdf0e10cSrcweir                     return eIndexList;
1140cdf0e10cSrcweir                 default:
1141cdf0e10cSrcweir                     break;
1142cdf0e10cSrcweir                 }
1143cdf0e10cSrcweir             }
1144cdf0e10cSrcweir             default:
1145cdf0e10cSrcweir                 break;
1146cdf0e10cSrcweir             }
1147cdf0e10cSrcweir             OSL_ENSURE( false, "lcl_getCurrentExchangeType: unsupported (unexpected) exchange type!" );
1148cdf0e10cSrcweir             return eEntry;
1149cdf0e10cSrcweir         }
1150cdf0e10cSrcweir     }
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir     //--------------------------------------------------------------------
translateExternalValueToControlValue(const Any & _rExternalValue) const1153cdf0e10cSrcweir     Any OListBoxModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
1154cdf0e10cSrcweir     {
1155cdf0e10cSrcweir         Sequence< sal_Int16 > aSelectIndexes;
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir         switch ( lcl_getCurrentExchangeType( getExternalValueType() ) )
1158cdf0e10cSrcweir         {
1159cdf0e10cSrcweir         case eIndexList:
1160cdf0e10cSrcweir         {
1161cdf0e10cSrcweir             // unfortunately, our select sequence is a sequence<short>, while the external binding
1162cdf0e10cSrcweir             // supplies sequence<int> only -> transform this
1163cdf0e10cSrcweir             Sequence< sal_Int32 > aSelectIndexesPure;
1164cdf0e10cSrcweir             OSL_VERIFY( _rExternalValue >>= aSelectIndexesPure );
1165cdf0e10cSrcweir             aSelectIndexes.realloc( aSelectIndexesPure.getLength() );
1166cdf0e10cSrcweir             ::std::copy(
1167cdf0e10cSrcweir                 aSelectIndexesPure.getConstArray(),
1168cdf0e10cSrcweir                 aSelectIndexesPure.getConstArray() + aSelectIndexesPure.getLength(),
1169cdf0e10cSrcweir                 aSelectIndexes.getArray()
1170cdf0e10cSrcweir             );
1171cdf0e10cSrcweir         }
1172cdf0e10cSrcweir         break;
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir         case eIndex:
1175cdf0e10cSrcweir         {
1176cdf0e10cSrcweir             sal_Int32 nSelectIndex = -1;
1177cdf0e10cSrcweir             OSL_VERIFY( _rExternalValue >>= nSelectIndex );
1178cdf0e10cSrcweir             if ( ( nSelectIndex >= 0 ) && ( nSelectIndex < getStringItemList().getLength() ) )
1179cdf0e10cSrcweir             {
1180cdf0e10cSrcweir                 aSelectIndexes.realloc( 1 );
1181cdf0e10cSrcweir                 aSelectIndexes[ 0 ] = static_cast< sal_Int16 >( nSelectIndex );
1182cdf0e10cSrcweir             }
1183cdf0e10cSrcweir         }
1184cdf0e10cSrcweir         break;
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir         case eEntryList:
1187cdf0e10cSrcweir         {
1188cdf0e10cSrcweir             // we can retrieve a string list from the binding for multiple selection
1189cdf0e10cSrcweir             Sequence< ::rtl::OUString > aSelectEntries;
1190cdf0e10cSrcweir             OSL_VERIFY( _rExternalValue >>= aSelectEntries );
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir             ::std::set< sal_Int16 > aSelectionSet;
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir             // find the selection entries in our item list
1195cdf0e10cSrcweir             const ::rtl::OUString* pSelectEntries = aSelectEntries.getArray();
1196cdf0e10cSrcweir             const ::rtl::OUString* pSelectEntriesEnd = pSelectEntries + aSelectEntries.getLength();
1197cdf0e10cSrcweir             while ( pSelectEntries != pSelectEntriesEnd )
1198cdf0e10cSrcweir             {
1199cdf0e10cSrcweir                 // the indexes where the current string appears in our string items
1200cdf0e10cSrcweir                 Sequence< sal_Int16 > aThisEntryIndexes;
1201cdf0e10cSrcweir                 aThisEntryIndexes = findValue( getStringItemList(), *pSelectEntries++, sal_False );
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir                 // insert all the indexes of this entry into our set
1204cdf0e10cSrcweir                 ::std::copy(
1205cdf0e10cSrcweir                     aThisEntryIndexes.getConstArray(),
1206cdf0e10cSrcweir                     aThisEntryIndexes.getConstArray() + aThisEntryIndexes.getLength(),
1207cdf0e10cSrcweir                     ::std::insert_iterator< ::std::set< sal_Int16 > >( aSelectionSet, aSelectionSet.begin() )
1208cdf0e10cSrcweir                 );
1209cdf0e10cSrcweir             }
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir             // copy the indexes to the sequence
1212cdf0e10cSrcweir             aSelectIndexes.realloc( aSelectionSet.size() );
1213cdf0e10cSrcweir             ::std::copy(
1214cdf0e10cSrcweir                 aSelectionSet.begin(),
1215cdf0e10cSrcweir                 aSelectionSet.end(),
1216cdf0e10cSrcweir                 aSelectIndexes.getArray()
1217cdf0e10cSrcweir             );
1218cdf0e10cSrcweir         }
1219cdf0e10cSrcweir         break;
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir         case eEntry:
1222cdf0e10cSrcweir         {
1223cdf0e10cSrcweir             ::rtl::OUString sStringToSelect;
1224cdf0e10cSrcweir             OSL_VERIFY( _rExternalValue >>= sStringToSelect );
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir             aSelectIndexes = findValue( getStringItemList(), sStringToSelect, sal_False );
1227cdf0e10cSrcweir         }
1228cdf0e10cSrcweir         break;
1229cdf0e10cSrcweir         }
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir         return makeAny( aSelectIndexes );
1232cdf0e10cSrcweir     }
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir     //--------------------------------------------------------------------
1235cdf0e10cSrcweir     namespace
1236cdf0e10cSrcweir     {
1237cdf0e10cSrcweir         //................................................................
1238cdf0e10cSrcweir         struct ExtractStringFromSequence_Safe : public ::std::unary_function< sal_Int16, ::rtl::OUString >
1239cdf0e10cSrcweir         {
1240cdf0e10cSrcweir         protected:
1241cdf0e10cSrcweir             const Sequence< ::rtl::OUString >&  m_rList;
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir         public:
ExtractStringFromSequence_Safefrm::__anonfa98e5550311::ExtractStringFromSequence_Safe1244cdf0e10cSrcweir             ExtractStringFromSequence_Safe( const Sequence< ::rtl::OUString >& _rList ) : m_rList( _rList ) { }
1245cdf0e10cSrcweir 
operator ()frm::__anonfa98e5550311::ExtractStringFromSequence_Safe1246cdf0e10cSrcweir             ::rtl::OUString operator ()( sal_Int16 _nIndex )
1247cdf0e10cSrcweir             {
1248cdf0e10cSrcweir                 OSL_ENSURE( _nIndex < m_rList.getLength(), "ExtractStringFromSequence_Safe: inconsistence!" );
1249cdf0e10cSrcweir                 if ( _nIndex < m_rList.getLength() )
1250cdf0e10cSrcweir                     return m_rList[ _nIndex ];
1251cdf0e10cSrcweir                 return ::rtl::OUString();
1252cdf0e10cSrcweir             }
1253cdf0e10cSrcweir         };
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir         //................................................................
lcl_getSingleSelectedEntry(const Sequence<sal_Int16> & _rSelectSequence,const Sequence<::rtl::OUString> & _rStringList)1256cdf0e10cSrcweir         Any lcl_getSingleSelectedEntry( const Sequence< sal_Int16 >& _rSelectSequence, const Sequence< ::rtl::OUString >& _rStringList )
1257cdf0e10cSrcweir         {
1258cdf0e10cSrcweir             Any aReturn;
1259cdf0e10cSrcweir 
1260*07a3d7f1SPedro Giffuni             // by definition, multiple selected entries are transferred as NULL if the
1261cdf0e10cSrcweir             // binding does not support string lists
1262cdf0e10cSrcweir             if ( _rSelectSequence.getLength() <= 1 )
1263cdf0e10cSrcweir             {
1264cdf0e10cSrcweir                 ::rtl::OUString sSelectedEntry;
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir                 if ( _rSelectSequence.getLength() == 1 )
1267cdf0e10cSrcweir                     sSelectedEntry = ExtractStringFromSequence_Safe( _rStringList )( _rSelectSequence[0] );
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir                 aReturn <<= sSelectedEntry;
1270cdf0e10cSrcweir             }
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir             return aReturn;
1273cdf0e10cSrcweir         }
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir         //................................................................
lcl_getMultiSelectedEntries(const Sequence<sal_Int16> & _rSelectSequence,const Sequence<::rtl::OUString> & _rStringList)1276cdf0e10cSrcweir         Any lcl_getMultiSelectedEntries( const Sequence< sal_Int16 >& _rSelectSequence, const Sequence< ::rtl::OUString >& _rStringList )
1277cdf0e10cSrcweir         {
1278cdf0e10cSrcweir             Sequence< ::rtl::OUString > aSelectedEntriesTexts( _rSelectSequence.getLength() );
1279cdf0e10cSrcweir             ::std::transform(
1280cdf0e10cSrcweir                 _rSelectSequence.getConstArray(),
1281cdf0e10cSrcweir                 _rSelectSequence.getConstArray() + _rSelectSequence.getLength(),
1282cdf0e10cSrcweir                 aSelectedEntriesTexts.getArray(),
1283cdf0e10cSrcweir                 ExtractStringFromSequence_Safe( _rStringList )
1284cdf0e10cSrcweir             );
1285cdf0e10cSrcweir             return makeAny( aSelectedEntriesTexts );
1286cdf0e10cSrcweir         }
1287cdf0e10cSrcweir     }
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir     //--------------------------------------------------------------------
translateControlValueToExternalValue() const1290cdf0e10cSrcweir     Any OListBoxModel::translateControlValueToExternalValue( ) const
1291cdf0e10cSrcweir     {
1292cdf0e10cSrcweir         OSL_PRECOND( hasExternalValueBinding(), "OListBoxModel::translateControlValueToExternalValue: no binding!" );
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir         Sequence< sal_Int16 > aSelectSequence;
1295cdf0e10cSrcweir         const_cast< OListBoxModel* >( this )->getPropertyValue( PROPERTY_SELECT_SEQ ) >>= aSelectSequence;
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir         Any aReturn;
1298cdf0e10cSrcweir         switch ( lcl_getCurrentExchangeType( getExternalValueType() ) )
1299cdf0e10cSrcweir         {
1300cdf0e10cSrcweir         case eIndexList:
1301cdf0e10cSrcweir         {
1302cdf0e10cSrcweir             // unfortunately, the select sequence is a sequence<short>, but our binding
1303cdf0e10cSrcweir             // expects int's
1304cdf0e10cSrcweir             Sequence< sal_Int32 > aTransformed( aSelectSequence.getLength() );
1305cdf0e10cSrcweir             ::std::copy(
1306cdf0e10cSrcweir                 aSelectSequence.getConstArray(),
1307cdf0e10cSrcweir                 aSelectSequence.getConstArray() + aSelectSequence.getLength(),
1308cdf0e10cSrcweir                 aTransformed.getArray()
1309cdf0e10cSrcweir             );
1310cdf0e10cSrcweir             aReturn <<= aTransformed;
1311cdf0e10cSrcweir         }
1312cdf0e10cSrcweir         break;
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir         case eIndex:
1315cdf0e10cSrcweir         if ( aSelectSequence.getLength() <= 1 )
1316cdf0e10cSrcweir         {
1317cdf0e10cSrcweir             sal_Int32 nIndex = -1;
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir             if ( aSelectSequence.getLength() == 1 )
1320cdf0e10cSrcweir                 nIndex = aSelectSequence[0];
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir             aReturn <<= nIndex;
1323cdf0e10cSrcweir         }
1324cdf0e10cSrcweir         break;
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir         case eEntryList:
1327cdf0e10cSrcweir             aReturn = lcl_getMultiSelectedEntries( aSelectSequence, getStringItemList() );
1328cdf0e10cSrcweir             break;
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir         case eEntry:
1331cdf0e10cSrcweir             aReturn = lcl_getSingleSelectedEntry( aSelectSequence, getStringItemList() );
1332cdf0e10cSrcweir             break;
1333cdf0e10cSrcweir         }
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir         return aReturn;
1336cdf0e10cSrcweir     }
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir     //--------------------------------------------------------------------
getCurrentFormComponentValue() const1339cdf0e10cSrcweir     Any OListBoxModel::getCurrentFormComponentValue() const
1340cdf0e10cSrcweir     {
1341cdf0e10cSrcweir         if ( hasValidator() )
1342cdf0e10cSrcweir             return OBoundControlModel::getCurrentFormComponentValue();
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir         Any aCurretnValue;
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir         try
1347cdf0e10cSrcweir         {
1348cdf0e10cSrcweir             Sequence< sal_Int16 > aSelectSequence;
1349cdf0e10cSrcweir             OSL_VERIFY( const_cast< OListBoxModel* >( this )->getPropertyValue( PROPERTY_SELECT_SEQ ) >>= aSelectSequence );
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir             sal_Bool bMultiSelection( sal_False );
1352cdf0e10cSrcweir             OSL_VERIFY( const_cast< OListBoxModel* >( this )->getPropertyValue( PROPERTY_MULTISELECTION ) >>= bMultiSelection );
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir             if ( bMultiSelection )
1355cdf0e10cSrcweir                 aCurretnValue = lcl_getMultiSelectedEntries( aSelectSequence, getStringItemList() );
1356cdf0e10cSrcweir             else
1357cdf0e10cSrcweir                 aCurretnValue = lcl_getSingleSelectedEntry( aSelectSequence, getStringItemList() );
1358cdf0e10cSrcweir         }
1359cdf0e10cSrcweir         catch( const Exception& )
1360cdf0e10cSrcweir         {
1361cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
1362cdf0e10cSrcweir         }
1363cdf0e10cSrcweir 
1364cdf0e10cSrcweir         return aCurretnValue;
1365cdf0e10cSrcweir     }
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedBindingTypes()1368cdf0e10cSrcweir     Sequence< Type > OListBoxModel::getSupportedBindingTypes()
1369cdf0e10cSrcweir     {
1370cdf0e10cSrcweir         Sequence< Type > aTypes(4);
1371cdf0e10cSrcweir         aTypes[0] = ::getCppuType( static_cast< Sequence< sal_Int32 >* >( NULL ) );
1372cdf0e10cSrcweir         aTypes[1] = ::getCppuType( static_cast< sal_Int32* >( NULL ) );
1373cdf0e10cSrcweir         aTypes[2] = ::getCppuType( static_cast< Sequence< ::rtl::OUString >* >( NULL ) );
1374cdf0e10cSrcweir         aTypes[3] = ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
1375cdf0e10cSrcweir         return aTypes;
1376cdf0e10cSrcweir     }
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir     //--------------------------------------------------------------------
stringItemListChanged(ControlModelLock & _rInstanceLock)1379cdf0e10cSrcweir     void OListBoxModel::stringItemListChanged( ControlModelLock& _rInstanceLock )
1380cdf0e10cSrcweir     {
1381cdf0e10cSrcweir         if ( !m_xAggregateSet.is() )
1382cdf0e10cSrcweir             return;
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir         suspendValueListening();
1385cdf0e10cSrcweir         try
1386cdf0e10cSrcweir         {
1387cdf0e10cSrcweir             m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( getStringItemList() ) );
1388cdf0e10cSrcweir         }
1389cdf0e10cSrcweir         catch( const Exception& )
1390cdf0e10cSrcweir         {
1391cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
1392cdf0e10cSrcweir         }
1393cdf0e10cSrcweir         resumeValueListening();
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir         // update the selection here
1396cdf0e10cSrcweir         if ( hasExternalValueBinding( ) )
1397cdf0e10cSrcweir             transferExternalValueToControl( _rInstanceLock );
1398cdf0e10cSrcweir         else
1399cdf0e10cSrcweir         {
1400cdf0e10cSrcweir             if ( hasField() )
1401cdf0e10cSrcweir             {
1402cdf0e10cSrcweir                 // TODO: update the selection in case we're bound to a database column
1403cdf0e10cSrcweir             }
1404cdf0e10cSrcweir             else
1405cdf0e10cSrcweir             {
1406cdf0e10cSrcweir                 if ( m_aDefaultSelectSeq.getLength() )
1407cdf0e10cSrcweir                     setControlValue( makeAny( m_aDefaultSelectSeq ), eOther );
1408cdf0e10cSrcweir             }
1409cdf0e10cSrcweir         }
1410cdf0e10cSrcweir     }
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir     //--------------------------------------------------------------------
connectedExternalListSource()1413cdf0e10cSrcweir     void OListBoxModel::connectedExternalListSource( )
1414cdf0e10cSrcweir     {
1415cdf0e10cSrcweir         // TODO?
1416cdf0e10cSrcweir     }
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir     //--------------------------------------------------------------------
disconnectedExternalListSource()1419cdf0e10cSrcweir     void OListBoxModel::disconnectedExternalListSource( )
1420cdf0e10cSrcweir     {
1421cdf0e10cSrcweir         // TODO: in case we're part of an already loaded form, we should probably simulate
1422cdf0e10cSrcweir         // an onConnectedDbColumn, so our list get's filled with the data as indicated
1423cdf0e10cSrcweir         // by our SQL-binding related properties
1424cdf0e10cSrcweir     }
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir     //--------------------------------------------------------------------
impl_refreshDbEntryList(bool _bForce)1427cdf0e10cSrcweir     void OListBoxModel::impl_refreshDbEntryList( bool _bForce )
1428cdf0e10cSrcweir     {
1429cdf0e10cSrcweir         DBG_ASSERT( !hasExternalListSource(), "OListBoxModel::impl_refreshDbEntryList: invalid call!" );
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir         if  (   !hasExternalListSource( )
1432cdf0e10cSrcweir             &&  ( m_eListSourceType != ListSourceType_VALUELIST )
1433cdf0e10cSrcweir             &&  ( m_xCursor.is() )
1434cdf0e10cSrcweir             )
1435cdf0e10cSrcweir         {
1436cdf0e10cSrcweir             loadData( _bForce );
1437cdf0e10cSrcweir         }
1438cdf0e10cSrcweir     }
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir     //--------------------------------------------------------------------
refreshInternalEntryList()1441cdf0e10cSrcweir     void OListBoxModel::refreshInternalEntryList()
1442cdf0e10cSrcweir     {
1443cdf0e10cSrcweir         impl_refreshDbEntryList( true );
1444cdf0e10cSrcweir         if ( hasField() && m_xCursor.is() )
1445cdf0e10cSrcweir             initFromField( m_xCursor );
1446cdf0e10cSrcweir     }
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir     //==================================================================
1449cdf0e10cSrcweir     // OListBoxControl
1450cdf0e10cSrcweir     //==================================================================
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir     //------------------------------------------------------------------
OListBoxControl_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)1453cdf0e10cSrcweir     InterfaceRef SAL_CALL OListBoxControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
1454cdf0e10cSrcweir     {
1455cdf0e10cSrcweir         return *(new OListBoxControl(_rxFactory));
1456cdf0e10cSrcweir     }
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir     //------------------------------------------------------------------------------
_getTypes()1459cdf0e10cSrcweir     Sequence< Type> OListBoxControl::_getTypes()
1460cdf0e10cSrcweir     {
1461cdf0e10cSrcweir         return TypeBag(
1462cdf0e10cSrcweir             OBoundControl::_getTypes(),
1463cdf0e10cSrcweir             OListBoxControl_BASE::getTypes()
1464cdf0e10cSrcweir         ).getTypes();
1465cdf0e10cSrcweir     }
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir     //------------------------------------------------------------------
queryAggregation(const Type & _rType)1468cdf0e10cSrcweir     Any SAL_CALL OListBoxControl::queryAggregation(const Type& _rType) throw (RuntimeException)
1469cdf0e10cSrcweir     {
1470cdf0e10cSrcweir         Any aReturn = OListBoxControl_BASE::queryInterface( _rType );
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir         if  (   !aReturn.hasValue()
1473cdf0e10cSrcweir             ||  _rType.equals( XTypeProvider::static_type() )
1474cdf0e10cSrcweir             )
1475cdf0e10cSrcweir             aReturn = OBoundControl::queryAggregation( _rType );
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir         return aReturn;
1478cdf0e10cSrcweir     }
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir     DBG_NAME(OListBoxControl);
1481cdf0e10cSrcweir     //------------------------------------------------------------------------------
OListBoxControl(const Reference<XMultiServiceFactory> & _rxFactory)1482cdf0e10cSrcweir     OListBoxControl::OListBoxControl(const Reference<XMultiServiceFactory>& _rxFactory)
1483cdf0e10cSrcweir         :OBoundControl( _rxFactory, VCL_CONTROL_LISTBOX, sal_False )
1484cdf0e10cSrcweir         ,m_aChangeListeners( m_aMutex )
1485cdf0e10cSrcweir         ,m_aItemListeners( m_aMutex )
1486cdf0e10cSrcweir         ,m_pItemBroadcaster( NULL )
1487cdf0e10cSrcweir     {
1488cdf0e10cSrcweir         DBG_CTOR(OListBoxControl,NULL);
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir         increment(m_refCount);
1491cdf0e10cSrcweir         {
1492cdf0e10cSrcweir             // als FocusListener anmelden
1493cdf0e10cSrcweir             Reference<XWindow> xComp;
1494cdf0e10cSrcweir             if (query_aggregation(m_xAggregate, xComp))
1495cdf0e10cSrcweir                 xComp->addFocusListener(this);
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir             // als ItemListener anmelden
1498cdf0e10cSrcweir             if ( query_aggregation( m_xAggregate, m_xAggregateListBox ) )
1499cdf0e10cSrcweir                 m_xAggregateListBox->addItemListener(this);
1500cdf0e10cSrcweir         }
1501cdf0e10cSrcweir         // Refcount bei 2 fuer angemeldete Listener
1502cdf0e10cSrcweir         decrement(m_refCount);
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir         doSetDelegator();
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir         m_aChangeTimer.SetTimeout(500);
1507cdf0e10cSrcweir         m_aChangeTimer.SetTimeoutHdl(LINK(this,OListBoxControl,OnTimeout));
1508cdf0e10cSrcweir     }
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir     //------------------------------------------------------------------------------
~OListBoxControl()1511cdf0e10cSrcweir     OListBoxControl::~OListBoxControl()
1512cdf0e10cSrcweir     {
1513cdf0e10cSrcweir         if (!OComponentHelper::rBHelper.bDisposed)
1514cdf0e10cSrcweir         {
1515cdf0e10cSrcweir             acquire();
1516cdf0e10cSrcweir             dispose();
1517cdf0e10cSrcweir         }
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir         doResetDelegator();
1520cdf0e10cSrcweir         m_xAggregateListBox.clear();
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir         DBG_DTOR(OListBoxControl,NULL);
1523cdf0e10cSrcweir     }
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir     //------------------------------------------------------------------------------
getSupportedServiceNames()1526cdf0e10cSrcweir     StringSequence SAL_CALL OListBoxControl::getSupportedServiceNames() throw(RuntimeException)
1527cdf0e10cSrcweir     {
1528cdf0e10cSrcweir         StringSequence aSupported = OBoundControl::getSupportedServiceNames();
1529cdf0e10cSrcweir         aSupported.realloc(aSupported.getLength() + 1);
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir         ::rtl::OUString* pArray = aSupported.getArray();
1532cdf0e10cSrcweir         pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_LISTBOX;
1533cdf0e10cSrcweir         return aSupported;
1534cdf0e10cSrcweir     }
1535cdf0e10cSrcweir 
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir     // XFocusListener
1538cdf0e10cSrcweir     //------------------------------------------------------------------------------
focusGained(const FocusEvent &)1539cdf0e10cSrcweir     void SAL_CALL OListBoxControl::focusGained(const FocusEvent& /*_rEvent*/) throw(RuntimeException)
1540cdf0e10cSrcweir     {
1541cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
1542cdf0e10cSrcweir         if ( m_aChangeListeners.getLength() ) // only if there are listeners
1543cdf0e10cSrcweir         {
1544cdf0e10cSrcweir             Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
1545cdf0e10cSrcweir             if (xSet.is())
1546cdf0e10cSrcweir             {
1547cdf0e10cSrcweir                 // memorize the current selection for posting the change event
1548cdf0e10cSrcweir                 m_aCurrentSelection = xSet->getPropertyValue(PROPERTY_SELECT_SEQ);
1549cdf0e10cSrcweir             }
1550cdf0e10cSrcweir         }
1551cdf0e10cSrcweir     }
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir     //------------------------------------------------------------------------------
focusLost(const FocusEvent &)1554cdf0e10cSrcweir     void SAL_CALL OListBoxControl::focusLost(const FocusEvent& /*_rEvent*/) throw(RuntimeException)
1555cdf0e10cSrcweir     {
1556cdf0e10cSrcweir         m_aCurrentSelection.clear();
1557cdf0e10cSrcweir     }
1558cdf0e10cSrcweir 
1559cdf0e10cSrcweir     // XItemListener
1560cdf0e10cSrcweir     //------------------------------------------------------------------------------
itemStateChanged(const ItemEvent & _rEvent)1561cdf0e10cSrcweir     void SAL_CALL OListBoxControl::itemStateChanged(const ItemEvent& _rEvent) throw(RuntimeException)
1562cdf0e10cSrcweir     {
1563cdf0e10cSrcweir         // forward this to our listeners
1564cdf0e10cSrcweir         {
1565cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
1566cdf0e10cSrcweir             if ( m_aItemListeners.getLength() )
1567cdf0e10cSrcweir             {
1568cdf0e10cSrcweir                 if ( !m_pItemBroadcaster.is() )
1569cdf0e10cSrcweir                 {
1570cdf0e10cSrcweir                     m_pItemBroadcaster.set( new ::comphelper::AsyncEventNotifier );
1571cdf0e10cSrcweir                     m_pItemBroadcaster->create();
1572cdf0e10cSrcweir                 }
1573cdf0e10cSrcweir 		        m_pItemBroadcaster->addEvent( new ItemEventDescription( _rEvent ), this );
1574cdf0e10cSrcweir             }
1575cdf0e10cSrcweir         }
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir         // and do the handling for the ChangeListeners
1578cdf0e10cSrcweir         ::osl::ClearableMutexGuard aGuard(m_aMutex);
1579cdf0e10cSrcweir         if ( m_aChangeTimer.IsActive() )
1580cdf0e10cSrcweir         {
1581cdf0e10cSrcweir             Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
1582cdf0e10cSrcweir             m_aCurrentSelection = xSet->getPropertyValue(PROPERTY_SELECT_SEQ);
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir             m_aChangeTimer.Stop();
1585cdf0e10cSrcweir             m_aChangeTimer.Start();
1586cdf0e10cSrcweir         }
1587cdf0e10cSrcweir         else
1588cdf0e10cSrcweir         {
1589cdf0e10cSrcweir             if ( m_aChangeListeners.getLength() && m_aCurrentSelection.hasValue() )
1590cdf0e10cSrcweir             {
1591cdf0e10cSrcweir                 Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
1592cdf0e10cSrcweir                 if (xSet.is())
1593cdf0e10cSrcweir                 {
1594cdf0e10cSrcweir                     // Has the selection been changed?
1595cdf0e10cSrcweir                     sal_Bool bModified(sal_False);
1596cdf0e10cSrcweir                     Any aValue = xSet->getPropertyValue(PROPERTY_SELECT_SEQ);
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir                     Sequence<sal_Int16>& rSelection = *(Sequence<sal_Int16> *)aValue.getValue();
1599cdf0e10cSrcweir                     Sequence<sal_Int16>& rOldSelection = *(Sequence<sal_Int16> *)m_aCurrentSelection.getValue();
1600cdf0e10cSrcweir                     sal_Int32 nLen = rSelection.getLength();
1601cdf0e10cSrcweir                     if (nLen != rOldSelection.getLength())
1602cdf0e10cSrcweir                         bModified = sal_True;
1603cdf0e10cSrcweir                     else
1604cdf0e10cSrcweir                     {
1605cdf0e10cSrcweir                         const sal_Int16* pVal = rSelection.getConstArray();
1606cdf0e10cSrcweir                         const sal_Int16* pCompVal = rOldSelection.getConstArray();
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir                         while (nLen-- && !bModified)
1609cdf0e10cSrcweir                             bModified = pVal[nLen] != pCompVal[nLen];
1610cdf0e10cSrcweir                     }
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir                     if (bModified)
1613cdf0e10cSrcweir                     {
1614cdf0e10cSrcweir                         m_aCurrentSelection = aValue;
1615cdf0e10cSrcweir                         m_aChangeTimer.Start();
1616cdf0e10cSrcweir                     }
1617cdf0e10cSrcweir                 }
1618cdf0e10cSrcweir             }
1619cdf0e10cSrcweir             else if (m_aCurrentSelection.hasValue())
1620cdf0e10cSrcweir                 m_aCurrentSelection.clear();
1621cdf0e10cSrcweir         }
1622cdf0e10cSrcweir     }
1623cdf0e10cSrcweir 
1624cdf0e10cSrcweir     // XEventListener
1625cdf0e10cSrcweir     //------------------------------------------------------------------------------
disposing(const EventObject & _rSource)1626cdf0e10cSrcweir     void SAL_CALL OListBoxControl::disposing(const EventObject& _rSource) throw (RuntimeException)
1627cdf0e10cSrcweir     {
1628cdf0e10cSrcweir         OBoundControl::disposing(_rSource);
1629cdf0e10cSrcweir     }
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir     // XChangeBroadcaster
1632cdf0e10cSrcweir     //------------------------------------------------------------------------------
addChangeListener(const Reference<XChangeListener> & _rxListener)1633cdf0e10cSrcweir     void SAL_CALL OListBoxControl::addChangeListener(const Reference<XChangeListener>& _rxListener) throw(RuntimeException)
1634cdf0e10cSrcweir     {
1635cdf0e10cSrcweir         m_aChangeListeners.addInterface( _rxListener );
1636cdf0e10cSrcweir     }
1637cdf0e10cSrcweir 
1638cdf0e10cSrcweir     //------------------------------------------------------------------------------
removeChangeListener(const Reference<XChangeListener> & _rxListener)1639cdf0e10cSrcweir     void SAL_CALL OListBoxControl::removeChangeListener(const Reference<XChangeListener>& _rxListener) throw(RuntimeException)
1640cdf0e10cSrcweir     {
1641cdf0e10cSrcweir         m_aChangeListeners.removeInterface( _rxListener );
1642cdf0e10cSrcweir     }
1643cdf0e10cSrcweir 
1644cdf0e10cSrcweir     // OComponentHelper
1645cdf0e10cSrcweir     //------------------------------------------------------------------------------
disposing()1646cdf0e10cSrcweir     void OListBoxControl::disposing()
1647cdf0e10cSrcweir     {
1648cdf0e10cSrcweir         if (m_aChangeTimer.IsActive())
1649cdf0e10cSrcweir             m_aChangeTimer.Stop();
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir         EventObject aEvent( *this );
1652cdf0e10cSrcweir         m_aChangeListeners.disposeAndClear( aEvent );
1653cdf0e10cSrcweir         m_aItemListeners.disposeAndClear( aEvent );
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir         {
1656cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
1657cdf0e10cSrcweir             if ( m_pItemBroadcaster.is() )
1658cdf0e10cSrcweir             {
1659cdf0e10cSrcweir                 m_pItemBroadcaster->removeEventsForProcessor( this );
1660cdf0e10cSrcweir                 m_pItemBroadcaster->terminate();
1661cdf0e10cSrcweir                 m_pItemBroadcaster = NULL;
1662cdf0e10cSrcweir             }
1663cdf0e10cSrcweir         }
1664cdf0e10cSrcweir 
1665cdf0e10cSrcweir         OBoundControl::disposing();
1666cdf0e10cSrcweir     }
1667cdf0e10cSrcweir 
1668cdf0e10cSrcweir     //------------------------------------------------------------------------------
processEvent(const AnyEvent & _rEvent)1669cdf0e10cSrcweir     void OListBoxControl::processEvent( const AnyEvent& _rEvent )
1670cdf0e10cSrcweir     {
1671cdf0e10cSrcweir         Reference< XListBox > xKeepAlive( this );
1672cdf0e10cSrcweir         {
1673cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
1674cdf0e10cSrcweir             if ( OComponentHelper::rBHelper.bDisposed )
1675cdf0e10cSrcweir                 return;
1676cdf0e10cSrcweir         }
1677cdf0e10cSrcweir         const ItemEventDescription& rItemEvent = static_cast< const ItemEventDescription& >( _rEvent );
1678cdf0e10cSrcweir         m_aItemListeners.notifyEach( &XItemListener::itemStateChanged, rItemEvent.getEventObject() );
1679cdf0e10cSrcweir     }
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir     //------------------------------------------------------------------------------
1682cdf0e10cSrcweir     IMPL_LINK(OListBoxControl, OnTimeout, void*, /*EMPTYTAG*/)
1683cdf0e10cSrcweir     {
1684cdf0e10cSrcweir         m_aChangeListeners.notifyEach( &XChangeListener::changed, EventObject( *this ) );
1685cdf0e10cSrcweir         return 0L;
1686cdf0e10cSrcweir     }
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir     //--------------------------------------------------------------------
addItemListener(const Reference<XItemListener> & l)1689cdf0e10cSrcweir     void SAL_CALL OListBoxControl::addItemListener( const Reference< XItemListener >& l ) throw (RuntimeException)
1690cdf0e10cSrcweir     {
1691cdf0e10cSrcweir         m_aItemListeners.addInterface( l );
1692cdf0e10cSrcweir     }
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir     //--------------------------------------------------------------------
removeItemListener(const Reference<XItemListener> & l)1695cdf0e10cSrcweir     void SAL_CALL OListBoxControl::removeItemListener( const Reference< XItemListener >& l ) throw (RuntimeException)
1696cdf0e10cSrcweir     {
1697cdf0e10cSrcweir         m_aItemListeners.removeInterface( l );
1698cdf0e10cSrcweir     }
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir     //--------------------------------------------------------------------
addActionListener(const Reference<XActionListener> & l)1701cdf0e10cSrcweir     void SAL_CALL OListBoxControl::addActionListener( const Reference< XActionListener >& l ) throw (RuntimeException)
1702cdf0e10cSrcweir     {
1703cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1704cdf0e10cSrcweir             m_xAggregateListBox->addActionListener( l );
1705cdf0e10cSrcweir     }
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir     //--------------------------------------------------------------------
removeActionListener(const Reference<XActionListener> & l)1708cdf0e10cSrcweir     void SAL_CALL OListBoxControl::removeActionListener( const Reference< XActionListener >& l ) throw (RuntimeException)
1709cdf0e10cSrcweir     {
1710cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1711cdf0e10cSrcweir             m_xAggregateListBox->removeActionListener( l );
1712cdf0e10cSrcweir     }
1713cdf0e10cSrcweir 
1714cdf0e10cSrcweir     //--------------------------------------------------------------------
addItem(const::rtl::OUString & aItem,::sal_Int16 nPos)1715cdf0e10cSrcweir     void SAL_CALL OListBoxControl::addItem( const ::rtl::OUString& aItem, ::sal_Int16 nPos ) throw (RuntimeException)
1716cdf0e10cSrcweir     {
1717cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1718cdf0e10cSrcweir             m_xAggregateListBox->addItem( aItem, nPos );
1719cdf0e10cSrcweir     }
1720cdf0e10cSrcweir 
1721cdf0e10cSrcweir     //--------------------------------------------------------------------
addItems(const Sequence<::rtl::OUString> & aItems,::sal_Int16 nPos)1722cdf0e10cSrcweir     void SAL_CALL OListBoxControl::addItems( const Sequence< ::rtl::OUString >& aItems, ::sal_Int16 nPos ) throw (RuntimeException)
1723cdf0e10cSrcweir     {
1724cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1725cdf0e10cSrcweir             m_xAggregateListBox->addItems( aItems, nPos );
1726cdf0e10cSrcweir     }
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir     //--------------------------------------------------------------------
removeItems(::sal_Int16 nPos,::sal_Int16 nCount)1729cdf0e10cSrcweir     void SAL_CALL OListBoxControl::removeItems( ::sal_Int16 nPos, ::sal_Int16 nCount ) throw (RuntimeException)
1730cdf0e10cSrcweir     {
1731cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1732cdf0e10cSrcweir             m_xAggregateListBox->removeItems( nPos, nCount );
1733cdf0e10cSrcweir     }
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir     //--------------------------------------------------------------------
getItemCount()1736cdf0e10cSrcweir     ::sal_Int16 SAL_CALL OListBoxControl::getItemCount(  ) throw (RuntimeException)
1737cdf0e10cSrcweir     {
1738cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1739cdf0e10cSrcweir             return m_xAggregateListBox->getItemCount();
1740cdf0e10cSrcweir         return 0;
1741cdf0e10cSrcweir     }
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir     //--------------------------------------------------------------------
getItem(::sal_Int16 nPos)1744cdf0e10cSrcweir     ::rtl::OUString SAL_CALL OListBoxControl::getItem( ::sal_Int16 nPos ) throw (RuntimeException)
1745cdf0e10cSrcweir     {
1746cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1747cdf0e10cSrcweir             return m_xAggregateListBox->getItem( nPos );
1748cdf0e10cSrcweir         return ::rtl::OUString( );
1749cdf0e10cSrcweir     }
1750cdf0e10cSrcweir 
1751cdf0e10cSrcweir     //--------------------------------------------------------------------
getItems()1752cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL OListBoxControl::getItems(  ) throw (RuntimeException)
1753cdf0e10cSrcweir     {
1754cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1755cdf0e10cSrcweir             return m_xAggregateListBox->getItems();
1756cdf0e10cSrcweir         return Sequence< ::rtl::OUString >( );
1757cdf0e10cSrcweir     }
1758cdf0e10cSrcweir 
1759cdf0e10cSrcweir     //--------------------------------------------------------------------
getSelectedItemPos()1760cdf0e10cSrcweir     ::sal_Int16 SAL_CALL OListBoxControl::getSelectedItemPos(  ) throw (RuntimeException)
1761cdf0e10cSrcweir     {
1762cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1763cdf0e10cSrcweir             return m_xAggregateListBox->getSelectedItemPos();
1764cdf0e10cSrcweir         return 0;
1765cdf0e10cSrcweir     }
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir     //--------------------------------------------------------------------
getSelectedItemsPos()1768cdf0e10cSrcweir     Sequence< ::sal_Int16 > SAL_CALL OListBoxControl::getSelectedItemsPos(  ) throw (RuntimeException)
1769cdf0e10cSrcweir     {
1770cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1771cdf0e10cSrcweir             return m_xAggregateListBox->getSelectedItemsPos();
1772cdf0e10cSrcweir         return Sequence< ::sal_Int16 >( );
1773cdf0e10cSrcweir     }
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir     //--------------------------------------------------------------------
getSelectedItem()1776cdf0e10cSrcweir     ::rtl::OUString SAL_CALL OListBoxControl::getSelectedItem(  ) throw (RuntimeException)
1777cdf0e10cSrcweir     {
1778cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1779cdf0e10cSrcweir             return m_xAggregateListBox->getSelectedItem();
1780cdf0e10cSrcweir         return ::rtl::OUString( );
1781cdf0e10cSrcweir     }
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir     //--------------------------------------------------------------------
getSelectedItems()1784cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL OListBoxControl::getSelectedItems(  ) throw (RuntimeException)
1785cdf0e10cSrcweir     {
1786cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1787cdf0e10cSrcweir             return m_xAggregateListBox->getSelectedItems();
1788cdf0e10cSrcweir         return Sequence< ::rtl::OUString >( );
1789cdf0e10cSrcweir     }
1790cdf0e10cSrcweir 
1791cdf0e10cSrcweir     //--------------------------------------------------------------------
selectItemPos(::sal_Int16 nPos,::sal_Bool bSelect)1792cdf0e10cSrcweir     void SAL_CALL OListBoxControl::selectItemPos( ::sal_Int16 nPos, ::sal_Bool bSelect ) throw (RuntimeException)
1793cdf0e10cSrcweir     {
1794cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1795cdf0e10cSrcweir             m_xAggregateListBox->selectItemPos( nPos, bSelect );
1796cdf0e10cSrcweir     }
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir     //--------------------------------------------------------------------
selectItemsPos(const Sequence<::sal_Int16> & aPositions,::sal_Bool bSelect)1799cdf0e10cSrcweir     void SAL_CALL OListBoxControl::selectItemsPos( const Sequence< ::sal_Int16 >& aPositions, ::sal_Bool bSelect ) throw (RuntimeException)
1800cdf0e10cSrcweir     {
1801cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1802cdf0e10cSrcweir             m_xAggregateListBox->selectItemsPos( aPositions, bSelect );
1803cdf0e10cSrcweir     }
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir     //--------------------------------------------------------------------
selectItem(const::rtl::OUString & aItem,::sal_Bool bSelect)1806cdf0e10cSrcweir     void SAL_CALL OListBoxControl::selectItem( const ::rtl::OUString& aItem, ::sal_Bool bSelect ) throw (RuntimeException)
1807cdf0e10cSrcweir     {
1808cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1809cdf0e10cSrcweir             m_xAggregateListBox->selectItem( aItem, bSelect );
1810cdf0e10cSrcweir     }
1811cdf0e10cSrcweir 
1812cdf0e10cSrcweir     //--------------------------------------------------------------------
isMutipleMode()1813cdf0e10cSrcweir     ::sal_Bool SAL_CALL OListBoxControl::isMutipleMode(  ) throw (RuntimeException)
1814cdf0e10cSrcweir     {
1815cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1816cdf0e10cSrcweir             return m_xAggregateListBox->isMutipleMode();
1817cdf0e10cSrcweir         return sal_False;
1818cdf0e10cSrcweir     }
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir     //--------------------------------------------------------------------
setMultipleMode(::sal_Bool bMulti)1821cdf0e10cSrcweir     void SAL_CALL OListBoxControl::setMultipleMode( ::sal_Bool bMulti ) throw (RuntimeException)
1822cdf0e10cSrcweir     {
1823cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1824cdf0e10cSrcweir             m_xAggregateListBox->setMultipleMode( bMulti );
1825cdf0e10cSrcweir     }
1826cdf0e10cSrcweir 
1827cdf0e10cSrcweir     //--------------------------------------------------------------------
getDropDownLineCount()1828cdf0e10cSrcweir     ::sal_Int16 SAL_CALL OListBoxControl::getDropDownLineCount(  ) throw (RuntimeException)
1829cdf0e10cSrcweir     {
1830cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1831cdf0e10cSrcweir             return m_xAggregateListBox->getDropDownLineCount();
1832cdf0e10cSrcweir         return 0;
1833cdf0e10cSrcweir     }
1834cdf0e10cSrcweir 
1835cdf0e10cSrcweir     //--------------------------------------------------------------------
setDropDownLineCount(::sal_Int16 nLines)1836cdf0e10cSrcweir     void SAL_CALL OListBoxControl::setDropDownLineCount( ::sal_Int16 nLines ) throw (RuntimeException)
1837cdf0e10cSrcweir     {
1838cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1839cdf0e10cSrcweir             m_xAggregateListBox->setDropDownLineCount( nLines );
1840cdf0e10cSrcweir     }
1841cdf0e10cSrcweir 
1842cdf0e10cSrcweir     //--------------------------------------------------------------------
makeVisible(::sal_Int16 nEntry)1843cdf0e10cSrcweir     void SAL_CALL OListBoxControl::makeVisible( ::sal_Int16 nEntry ) throw (RuntimeException)
1844cdf0e10cSrcweir     {
1845cdf0e10cSrcweir         if ( m_xAggregateListBox.is() )
1846cdf0e10cSrcweir             m_xAggregateListBox->makeVisible( nEntry );
1847cdf0e10cSrcweir     }
1848cdf0e10cSrcweir 
1849cdf0e10cSrcweir //.........................................................................
1850cdf0e10cSrcweir }
1851cdf0e10cSrcweir //.........................................................................
1852cdf0e10cSrcweir 
1853