1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "ComboBox.hxx"
28cdf0e10cSrcweir #include "property.hxx"
29cdf0e10cSrcweir #include "property.hrc"
30cdf0e10cSrcweir #include "services.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "frm_resource.hxx"
33cdf0e10cSrcweir #include "frm_resource.hrc"
34cdf0e10cSrcweir #include "BaseListBox.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /** === begin UNO includes === **/
37cdf0e10cSrcweir #include <com/sun/star/sdb/SQLErrorEvent.hpp>
38cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.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/sdbc/XConnection.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
47cdf0e10cSrcweir /** === end UNO includes === **/
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <comphelper/numbers.hxx>
50cdf0e10cSrcweir #include <comphelper/basicio.hxx>
51cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
52cdf0e10cSrcweir #include <connectivity/dbconversion.hxx>
53cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
54cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
55cdf0e10cSrcweir #include <tools/debug.hxx>
56cdf0e10cSrcweir #include <tools/diagnose_ex.h>
57cdf0e10cSrcweir #include <unotools/sharedunocomponent.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include <limits.h>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir using namespace dbtools;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir //.........................................................................
64cdf0e10cSrcweir namespace frm
65cdf0e10cSrcweir {
66cdf0e10cSrcweir using namespace ::com::sun::star::uno;
67cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
68cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
69cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
70cdf0e10cSrcweir using namespace ::com::sun::star::beans;
71cdf0e10cSrcweir using namespace ::com::sun::star::container;
72cdf0e10cSrcweir using namespace ::com::sun::star::form;
73cdf0e10cSrcweir using namespace ::com::sun::star::awt;
74cdf0e10cSrcweir using namespace ::com::sun::star::io;
75cdf0e10cSrcweir using namespace ::com::sun::star::lang;
76cdf0e10cSrcweir using namespace ::com::sun::star::util;
77cdf0e10cSrcweir using namespace ::com::sun::star::form::binding;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir //========================================================================
80cdf0e10cSrcweir // class OComboBoxModel
81cdf0e10cSrcweir //========================================================================
82cdf0e10cSrcweir //------------------------------------------------------------------
OComboBoxModel_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)83cdf0e10cSrcweir InterfaceRef SAL_CALL OComboBoxModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	return (*new OComboBoxModel(_rxFactory));
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir //------------------------------------------------------------------------------
_getTypes()89cdf0e10cSrcweir Sequence<Type> OComboBoxModel::_getTypes()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	return ::comphelper::concatSequences(
92cdf0e10cSrcweir 		OBoundControlModel::_getTypes(),
93cdf0e10cSrcweir         OEntryListHelper::getTypes(),
94cdf0e10cSrcweir 		OErrorBroadcaster::getTypes()
95cdf0e10cSrcweir 	);
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir // XServiceInfo
99cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames()100cdf0e10cSrcweir StringSequence SAL_CALL OComboBoxModel::getSupportedServiceNames() throw(RuntimeException)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     sal_Int32 nOldLen = aSupported.getLength();
105cdf0e10cSrcweir 	aSupported.realloc( nOldLen + 8 );
106cdf0e10cSrcweir 	::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
109cdf0e10cSrcweir     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
110cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
113cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_COMBOBOX;
116cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_COMBOBOX;
117cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATABASE_COMBO_BOX;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	return aSupported;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //------------------------------------------------------------------------------
queryAggregation(const Type & _rType)123cdf0e10cSrcweir Any SAL_CALL OComboBoxModel::queryAggregation(const Type& _rType) throw (RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	Any aReturn = OBoundControlModel::queryAggregation( _rType );
126cdf0e10cSrcweir     if ( !aReturn.hasValue() )
127cdf0e10cSrcweir         aReturn = OEntryListHelper::queryInterface( _rType );
128cdf0e10cSrcweir     if ( !aReturn.hasValue() )
129cdf0e10cSrcweir         aReturn = OErrorBroadcaster::queryInterface( _rType );
130cdf0e10cSrcweir     return aReturn;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir //------------------------------------------------------------------
DBG_NAME(OComboBoxModel)134cdf0e10cSrcweir DBG_NAME( OComboBoxModel )
135cdf0e10cSrcweir //------------------------------------------------------------------
136cdf0e10cSrcweir OComboBoxModel::OComboBoxModel(const Reference<XMultiServiceFactory>& _rxFactory)
137cdf0e10cSrcweir 	:OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_COMBOBOX, FRM_SUN_CONTROL_COMBOBOX, sal_True, sal_True, sal_True )
138cdf0e10cSrcweir 					// use the old control name for compytibility reasons
139cdf0e10cSrcweir     ,OEntryListHelper( (OControlModel&)*this )
140cdf0e10cSrcweir 	,OErrorBroadcaster( OComponentHelper::rBHelper )
141cdf0e10cSrcweir     ,m_aListRowSet( getContext() )
142cdf0e10cSrcweir 	,m_eListSourceType(ListSourceType_TABLE)
143cdf0e10cSrcweir 	,m_bEmptyIsNull(sal_True)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	DBG_CTOR( OComboBoxModel, NULL );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	m_nClassId = FormComponentType::COMBOBOX;
148cdf0e10cSrcweir     initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir //------------------------------------------------------------------
OComboBoxModel(const OComboBoxModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)152cdf0e10cSrcweir OComboBoxModel::OComboBoxModel( const OComboBoxModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
153cdf0e10cSrcweir 	:OBoundControlModel( _pOriginal, _rxFactory )
154cdf0e10cSrcweir     ,OEntryListHelper( *_pOriginal, (OControlModel&)*this )
155cdf0e10cSrcweir 	,OErrorBroadcaster( OComponentHelper::rBHelper )
156cdf0e10cSrcweir     ,m_aListRowSet( getContext() )
157cdf0e10cSrcweir 	,m_aListSource( _pOriginal->m_aListSource )
158cdf0e10cSrcweir 	,m_aDefaultText( _pOriginal->m_aDefaultText )
159cdf0e10cSrcweir 	,m_eListSourceType( _pOriginal->m_eListSourceType )
160cdf0e10cSrcweir 	,m_bEmptyIsNull( _pOriginal->m_bEmptyIsNull )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	DBG_CTOR( OComboBoxModel, NULL );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //------------------------------------------------------------------
~OComboBoxModel()166cdf0e10cSrcweir OComboBoxModel::~OComboBoxModel()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	if (!OComponentHelper::rBHelper.bDisposed)
169cdf0e10cSrcweir 	{
170cdf0e10cSrcweir 		acquire();
171cdf0e10cSrcweir 		dispose();
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	DBG_DTOR( OComboBoxModel, NULL );
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // XCloneable
178cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(OComboBoxModel)179cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OComboBoxModel )
180cdf0e10cSrcweir 
181cdf0e10cSrcweir //------------------------------------------------------------------------------
182cdf0e10cSrcweir void OComboBoxModel::disposing()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	OBoundControlModel::disposing();
185cdf0e10cSrcweir     OEntryListHelper::disposing();
186cdf0e10cSrcweir 	OErrorBroadcaster::disposing();
187cdf0e10cSrcweir 	m_xFormatter = NULL;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //------------------------------------------------------------------------------
getFastPropertyValue(Any & _rValue,sal_Int32 _nHandle) const191cdf0e10cSrcweir void OComboBoxModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
192cdf0e10cSrcweir {
193cdf0e10cSrcweir 	switch (_nHandle)
194cdf0e10cSrcweir 	{
195cdf0e10cSrcweir         case PROPERTY_ID_LISTSOURCETYPE:
196cdf0e10cSrcweir             _rValue <<= m_eListSourceType;
197cdf0e10cSrcweir             break;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 		case PROPERTY_ID_LISTSOURCE:
200cdf0e10cSrcweir             _rValue <<= m_aListSource;
201cdf0e10cSrcweir             break;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         case PROPERTY_ID_EMPTY_IS_NULL:
204cdf0e10cSrcweir             _rValue <<= m_bEmptyIsNull;
205cdf0e10cSrcweir             break;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         case PROPERTY_ID_DEFAULT_TEXT:
208cdf0e10cSrcweir             _rValue <<= m_aDefaultText;
209cdf0e10cSrcweir             break;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         case PROPERTY_ID_STRINGITEMLIST:
212cdf0e10cSrcweir             _rValue <<= getStringItemList();
213cdf0e10cSrcweir             break;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 		default:
216cdf0e10cSrcweir 			OBoundControlModel::getFastPropertyValue(_rValue, _nHandle);
217cdf0e10cSrcweir 	}
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir //------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any & _rValue)221cdf0e10cSrcweir void OComboBoxModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue)
222cdf0e10cSrcweir 						throw (Exception)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	switch (_nHandle)
225cdf0e10cSrcweir 	{
226cdf0e10cSrcweir 		case PROPERTY_ID_LISTSOURCETYPE :
227cdf0e10cSrcweir 			DBG_ASSERT(_rValue.getValueType().equals(::getCppuType(reinterpret_cast<ListSourceType*>(NULL))),
228cdf0e10cSrcweir 				"OComboBoxModel::setFastPropertyValue_NoBroadcast : invalid type !" );
229cdf0e10cSrcweir 			_rValue >>= m_eListSourceType;
230cdf0e10cSrcweir 			break;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 		case PROPERTY_ID_LISTSOURCE :
233cdf0e10cSrcweir 			DBG_ASSERT(_rValue.getValueType().getTypeClass() == TypeClass_STRING,
234cdf0e10cSrcweir 				"OComboBoxModel::setFastPropertyValue_NoBroadcast : invalid type !" );
235cdf0e10cSrcweir 			_rValue >>= m_aListSource;
236cdf0e10cSrcweir 			// die ListSource hat sich geaendert -> neu laden
237cdf0e10cSrcweir 			if (ListSourceType_VALUELIST != m_eListSourceType)
238cdf0e10cSrcweir 			{
239cdf0e10cSrcweir 				if ( m_xCursor.is() && !hasField() && !hasExternalListSource() )
240cdf0e10cSrcweir                     // combo box is already connected to a database, and no external list source
241cdf0e10cSrcweir 				    // data source changed -> refresh
242cdf0e10cSrcweir                     loadData( false );
243cdf0e10cSrcweir 			}
244cdf0e10cSrcweir 			break;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 		case PROPERTY_ID_EMPTY_IS_NULL :
247cdf0e10cSrcweir 			DBG_ASSERT(_rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN,
248cdf0e10cSrcweir 				"OComboBoxModel::setFastPropertyValue_NoBroadcast : invalid type !" );
249cdf0e10cSrcweir 			_rValue >>= m_bEmptyIsNull;
250cdf0e10cSrcweir 			break;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 		case PROPERTY_ID_DEFAULT_TEXT :
253cdf0e10cSrcweir 			DBG_ASSERT(_rValue.getValueType().getTypeClass() == TypeClass_STRING,
254cdf0e10cSrcweir 				"OComboBoxModel::setFastPropertyValue_NoBroadcast : invalid type !" );
255cdf0e10cSrcweir 			_rValue >>= m_aDefaultText;
256cdf0e10cSrcweir 			resetNoBroadcast();
257cdf0e10cSrcweir 			break;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         case PROPERTY_ID_STRINGITEMLIST:
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             ControlModelLock aLock( *this );
262cdf0e10cSrcweir             setNewStringItemList( _rValue, aLock );
263cdf0e10cSrcweir                 // TODO: this is bogus. setNewStringItemList expects a guard which has the *only*
264cdf0e10cSrcweir                 // lock to the mutex, but setFastPropertyValue_NoBroadcast is already called with
265cdf0e10cSrcweir                 // a lock - so we effectively has two locks here, of which setNewStringItemList can
266cdf0e10cSrcweir                 // only control one.
267cdf0e10cSrcweir         }
268cdf0e10cSrcweir         break;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 		default:
271cdf0e10cSrcweir 			OBoundControlModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
272cdf0e10cSrcweir 	}
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir //------------------------------------------------------------------------------
convertFastPropertyValue(Any & _rConvertedValue,Any & _rOldValue,sal_Int32 _nHandle,const Any & _rValue)276cdf0e10cSrcweir sal_Bool OComboBoxModel::convertFastPropertyValue(
277cdf0e10cSrcweir 						Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue)
278cdf0e10cSrcweir 						throw (IllegalArgumentException)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	sal_Bool bModified(sal_False);
281cdf0e10cSrcweir 	switch (_nHandle)
282cdf0e10cSrcweir 	{
283cdf0e10cSrcweir 		case PROPERTY_ID_LISTSOURCETYPE :
284cdf0e10cSrcweir 			bModified = tryPropertyValueEnum(_rConvertedValue, _rOldValue, _rValue, m_eListSourceType);
285cdf0e10cSrcweir 			break;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 		case PROPERTY_ID_LISTSOURCE :
288cdf0e10cSrcweir 			bModified = tryPropertyValue(_rConvertedValue, _rOldValue, _rValue, m_aListSource);
289cdf0e10cSrcweir 			break;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 		case PROPERTY_ID_EMPTY_IS_NULL :
292cdf0e10cSrcweir 			bModified = tryPropertyValue(_rConvertedValue, _rOldValue, _rValue, m_bEmptyIsNull);
293cdf0e10cSrcweir 			break;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 		case PROPERTY_ID_DEFAULT_TEXT :
296cdf0e10cSrcweir 			bModified = tryPropertyValue(_rConvertedValue, _rOldValue, _rValue, m_aDefaultText);
297cdf0e10cSrcweir 			break;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir         case PROPERTY_ID_STRINGITEMLIST:
300cdf0e10cSrcweir             bModified = convertNewListSourceProperty( _rConvertedValue, _rOldValue, _rValue );
301cdf0e10cSrcweir             break;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 		default:
304cdf0e10cSrcweir 			bModified = OBoundControlModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
305cdf0e10cSrcweir 			break;
306cdf0e10cSrcweir 	}
307cdf0e10cSrcweir 	return bModified;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const311cdf0e10cSrcweir void OComboBoxModel::describeFixedProperties( Sequence< Property >& _rProps ) const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir 	BEGIN_DESCRIBE_PROPERTIES( 6, OBoundControlModel )
314cdf0e10cSrcweir 		DECL_PROP1(TABINDEX,			sal_Int16,					BOUND);
315cdf0e10cSrcweir 		DECL_PROP1(LISTSOURCETYPE,		ListSourceType, BOUND);
316cdf0e10cSrcweir 		DECL_PROP1(LISTSOURCE,			::rtl::OUString,			BOUND);
317cdf0e10cSrcweir 		DECL_BOOL_PROP1(EMPTY_IS_NULL,								BOUND);
318cdf0e10cSrcweir 		DECL_PROP1(DEFAULT_TEXT,		::rtl::OUString,			BOUND);
319cdf0e10cSrcweir         DECL_PROP1(STRINGITEMLIST,      Sequence< ::rtl::OUString >,BOUND);
320cdf0e10cSrcweir 	END_DESCRIBE_PROPERTIES();
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir //------------------------------------------------------------------------------
describeAggregateProperties(Sequence<Property> & _rAggregateProps) const324cdf0e10cSrcweir void OComboBoxModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     OBoundControlModel::describeAggregateProperties( _rAggregateProps );
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     // superseded properties:
329cdf0e10cSrcweir     RemoveProperty( _rAggregateProps, PROPERTY_STRINGITEMLIST );
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir //------------------------------------------------------------------------------
getServiceName()333cdf0e10cSrcweir ::rtl::OUString SAL_CALL OComboBoxModel::getServiceName() throw(RuntimeException)
334cdf0e10cSrcweir {
335cdf0e10cSrcweir 	return FRM_COMPONENT_COMBOBOX;	// old (non-sun) name for compatibility !
336cdf0e10cSrcweir }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir //------------------------------------------------------------------------------
write(const Reference<stario::XObjectOutputStream> & _rxOutStream)339cdf0e10cSrcweir void SAL_CALL OComboBoxModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream)
340cdf0e10cSrcweir 		throw(stario::IOException, RuntimeException)
341cdf0e10cSrcweir {
342cdf0e10cSrcweir 	OBoundControlModel::write(_rxOutStream);
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 	// Version
345cdf0e10cSrcweir 	// Version 0x0002:	EmptyIsNull
346cdf0e10cSrcweir 	// Version 0x0003:	ListSource->Seq
347cdf0e10cSrcweir 	// Version 0x0004:	DefaultText
348cdf0e10cSrcweir 	// Version 0x0005:	HelpText
349cdf0e10cSrcweir 	_rxOutStream->writeShort(0x0006);
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 	// Maskierung fuer any
352cdf0e10cSrcweir 	sal_uInt16 nAnyMask = 0;
353cdf0e10cSrcweir 	if (m_aBoundColumn.getValueType().getTypeClass() == TypeClass_SHORT)
354cdf0e10cSrcweir 		nAnyMask |= BOUNDCOLUMN;
355cdf0e10cSrcweir 	_rxOutStream << nAnyMask;
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	StringSequence aListSourceSeq(&m_aListSource, 1);
358cdf0e10cSrcweir 	_rxOutStream << aListSourceSeq;
359cdf0e10cSrcweir 	_rxOutStream << (sal_Int16)m_eListSourceType;
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 	if ((nAnyMask & BOUNDCOLUMN) == BOUNDCOLUMN)
362cdf0e10cSrcweir 	{
363cdf0e10cSrcweir 		sal_Int16 nBoundColumn = 0;
364cdf0e10cSrcweir 		m_aBoundColumn >>= nBoundColumn;
365cdf0e10cSrcweir 		_rxOutStream << nBoundColumn;
366cdf0e10cSrcweir 	}
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 	_rxOutStream << (sal_Bool)m_bEmptyIsNull;
369cdf0e10cSrcweir 	_rxOutStream << m_aDefaultText;
370cdf0e10cSrcweir 	writeHelpTextCompatibly(_rxOutStream);
371cdf0e10cSrcweir 
372cdf0e10cSrcweir 	// from version 0x0006 : common properties
373cdf0e10cSrcweir 	writeCommonProperties(_rxOutStream);
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir //------------------------------------------------------------------------------
read(const Reference<stario::XObjectInputStream> & _rxInStream)377cdf0e10cSrcweir void SAL_CALL OComboBoxModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw(stario::IOException, RuntimeException)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir 	OBoundControlModel::read(_rxInStream);
380cdf0e10cSrcweir 	ControlModelLock aLock( *this );
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     // since we are "overwriting" the StringItemList of our aggregate (means we have
383cdf0e10cSrcweir     // an own place to store the value, instead of relying on our aggregate storing it),
384cdf0e10cSrcweir     // we need to respect what the aggregate just read for the StringItemList property.
385cdf0e10cSrcweir     try
386cdf0e10cSrcweir     {
387cdf0e10cSrcweir         if ( m_xAggregateSet.is() )
388cdf0e10cSrcweir             setNewStringItemList( m_xAggregateSet->getPropertyValue( PROPERTY_STRINGITEMLIST ), aLock );
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir     catch( const Exception& )
391cdf0e10cSrcweir     {
392cdf0e10cSrcweir     	OSL_ENSURE( sal_False, "OComboBoxModel::read: caught an exception while examining the aggregate's string item list!" );
393cdf0e10cSrcweir     }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	// Version
396cdf0e10cSrcweir 	sal_uInt16 nVersion = _rxInStream->readShort();
397cdf0e10cSrcweir 	DBG_ASSERT(nVersion > 0, "OComboBoxModel::read : version 0 ? this should never have been written !");
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	if (nVersion > 0x0006)
400cdf0e10cSrcweir 	{
401cdf0e10cSrcweir 		DBG_ERROR("OComboBoxModel::read : invalid (means unknown) version !");
402cdf0e10cSrcweir 		m_aListSource = ::rtl::OUString();
403cdf0e10cSrcweir 		m_aBoundColumn <<= (sal_Int16)0;
404cdf0e10cSrcweir 		m_aDefaultText = ::rtl::OUString();
405cdf0e10cSrcweir 		m_eListSourceType = ListSourceType_TABLE;
406cdf0e10cSrcweir 		m_bEmptyIsNull = sal_True;
407cdf0e10cSrcweir 		defaultCommonProperties();
408cdf0e10cSrcweir 		return;
409cdf0e10cSrcweir 	}
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 	// Maskierung fuer any
412cdf0e10cSrcweir 	sal_uInt16 nAnyMask;
413cdf0e10cSrcweir 	_rxInStream >> nAnyMask;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	// ListSource
416cdf0e10cSrcweir 	if (nVersion < 0x0003)
417cdf0e10cSrcweir 	{
418cdf0e10cSrcweir 		::rtl::OUString sListSource;
419cdf0e10cSrcweir 		_rxInStream >> m_aListSource;
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir 	else // nVersion == 4
422cdf0e10cSrcweir 	{
423cdf0e10cSrcweir 		m_aListSource = ::rtl::OUString();
424cdf0e10cSrcweir 		StringSequence aListSource;
425cdf0e10cSrcweir 		_rxInStream >> aListSource;
426cdf0e10cSrcweir 		const ::rtl::OUString* pToken = aListSource.getConstArray();
427cdf0e10cSrcweir 		sal_Int32 nLen = aListSource.getLength();
428cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < nLen; ++i, ++pToken)
429cdf0e10cSrcweir 			m_aListSource += *pToken;
430cdf0e10cSrcweir 	}
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	sal_Int16 nListSourceType;
433cdf0e10cSrcweir 	_rxInStream >> nListSourceType;
434cdf0e10cSrcweir 	m_eListSourceType = (ListSourceType)nListSourceType;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	if ((nAnyMask & BOUNDCOLUMN) == BOUNDCOLUMN)
437cdf0e10cSrcweir 	{
438cdf0e10cSrcweir 		sal_Int16 nValue;
439cdf0e10cSrcweir 		_rxInStream >> nValue;
440cdf0e10cSrcweir 		m_aBoundColumn <<= nValue;
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	if (nVersion > 0x0001)
444cdf0e10cSrcweir 	{
445cdf0e10cSrcweir 		sal_Bool bNull;
446cdf0e10cSrcweir 		_rxInStream >> bNull;
447cdf0e10cSrcweir 		m_bEmptyIsNull = bNull;
448cdf0e10cSrcweir 	}
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 	if (nVersion > 0x0003)	// nVersion == 4
451cdf0e10cSrcweir 		_rxInStream >> m_aDefaultText;
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     // Stringliste muss geleert werden, wenn eine Listenquelle gesetzt ist
454cdf0e10cSrcweir 	// dieses kann der Fall sein wenn im alive modus gespeichert wird
455cdf0e10cSrcweir 	if  (   m_aListSource.getLength()
456cdf0e10cSrcweir         &&  !hasExternalListSource()
457cdf0e10cSrcweir         )
458cdf0e10cSrcweir 	{
459cdf0e10cSrcweir     	setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( StringSequence() ) );
460cdf0e10cSrcweir 	}
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 	if (nVersion > 0x0004)
463cdf0e10cSrcweir 		readHelpTextCompatibly(_rxInStream);
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	if (nVersion > 0x0005)
466cdf0e10cSrcweir 		readCommonProperties(_rxInStream);
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	// Nach dem Lesen die Defaultwerte anzeigen
469cdf0e10cSrcweir 	if ( getControlSource().getLength() )
470cdf0e10cSrcweir 	{
471cdf0e10cSrcweir 		// (not if we don't have a control source - the "State" property acts like it is persistent, then
472cdf0e10cSrcweir 		resetNoBroadcast();
473cdf0e10cSrcweir 	}
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir //------------------------------------------------------------------------------
loadData(bool _bForce)477cdf0e10cSrcweir void OComboBoxModel::loadData( bool _bForce )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir 	DBG_ASSERT(m_eListSourceType != ListSourceType_VALUELIST, "OComboBoxModel::loadData : do not call for a value list !");
480cdf0e10cSrcweir     DBG_ASSERT( !hasExternalListSource(), "OComboBoxModel::loadData: cannot load from DB when I have an external list source!" );
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     if ( hasExternalListSource() )
483cdf0e10cSrcweir         return;
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 	// Connection holen
486cdf0e10cSrcweir 	Reference<XRowSet> xForm(m_xCursor, UNO_QUERY);
487cdf0e10cSrcweir 	if (!xForm.is())
488cdf0e10cSrcweir 		return;
489cdf0e10cSrcweir 	Reference<XConnection> xConnection = getConnection(xForm);
490cdf0e10cSrcweir 	if (!xConnection.is())
491cdf0e10cSrcweir 		return;
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 	Reference<XServiceInfo> xServiceInfo(xConnection, UNO_QUERY);
494cdf0e10cSrcweir 	if (!xServiceInfo.is() || !xServiceInfo->supportsService(SRV_SDB_CONNECTION))
495cdf0e10cSrcweir 	{
496cdf0e10cSrcweir 		DBG_ERROR("OComboBoxModel::loadData : invalid connection !");
497cdf0e10cSrcweir 		return;
498cdf0e10cSrcweir 	}
499cdf0e10cSrcweir 
500cdf0e10cSrcweir     if (!m_aListSource.getLength() || m_eListSourceType == ListSourceType_VALUELIST)
501cdf0e10cSrcweir 		return;
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     ::utl::SharedUNOComponent< XResultSet > xListCursor;
504cdf0e10cSrcweir 	try
505cdf0e10cSrcweir 	{
506cdf0e10cSrcweir         m_aListRowSet.setConnection( xConnection );
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         bool bExecuteRowSet( false );
509cdf0e10cSrcweir 		switch (m_eListSourceType)
510cdf0e10cSrcweir 		{
511cdf0e10cSrcweir 			case ListSourceType_TABLEFIELDS:
512cdf0e10cSrcweir 				// don't work with a statement here, the fields will be collected below
513cdf0e10cSrcweir 				break;
514cdf0e10cSrcweir 			case ListSourceType_TABLE:
515cdf0e10cSrcweir 			{
516cdf0e10cSrcweir 				// does the bound field belong to the table ?
517cdf0e10cSrcweir 				// if we use an alias for the bound field, we won't find it
518cdf0e10cSrcweir 				// in that case we use the first field of the table
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 				Reference<XNameAccess> xFieldsByName = getTableFields(xConnection, m_aListSource);
521cdf0e10cSrcweir 				Reference<XIndexAccess> xFieldsByIndex(xFieldsByName, UNO_QUERY);
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 				::rtl::OUString aFieldName;
524cdf0e10cSrcweir 				if ( xFieldsByName.is() && xFieldsByName->hasByName( getControlSource() ) )
525cdf0e10cSrcweir 				{
526cdf0e10cSrcweir 					aFieldName = getControlSource();
527cdf0e10cSrcweir 				}
528cdf0e10cSrcweir 				else
529cdf0e10cSrcweir 				{
530cdf0e10cSrcweir                     // otherwise look for the alias
531cdf0e10cSrcweir                     Reference<XPropertySet> xFormProp(xForm,UNO_QUERY);
532cdf0e10cSrcweir                     Reference< XColumnsSupplier > xSupplyFields;
533cdf0e10cSrcweir                     xFormProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupplyFields;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 					// search the field
536cdf0e10cSrcweir 					DBG_ASSERT(xSupplyFields.is(), "OComboBoxModel::loadData : invalid query composer !");
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 					Reference< XNameAccess > xFieldNames = xSupplyFields->getColumns();
539cdf0e10cSrcweir 					if ( xFieldNames->hasByName( getControlSource() ) )
540cdf0e10cSrcweir 					{
541cdf0e10cSrcweir                         Reference< XPropertySet > xComposerFieldAsSet;
542cdf0e10cSrcweir                         xFieldNames->getByName( getControlSource() ) >>= xComposerFieldAsSet;
543cdf0e10cSrcweir 						if (hasProperty(PROPERTY_FIELDSOURCE, xComposerFieldAsSet))
544cdf0e10cSrcweir 							xComposerFieldAsSet->getPropertyValue(PROPERTY_FIELDSOURCE) >>= aFieldName;
545cdf0e10cSrcweir 					}
546cdf0e10cSrcweir 				}
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 				if (!aFieldName.getLength())
549cdf0e10cSrcweir 					break;
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 				Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
552cdf0e10cSrcweir 				OSL_ENSURE(xMeta.is(),"No database meta data!");
553cdf0e10cSrcweir 				if ( xMeta.is() )
554cdf0e10cSrcweir 				{
555cdf0e10cSrcweir 					::rtl::OUString aQuote = xMeta->getIdentifierQuoteString();
556cdf0e10cSrcweir 
557cdf0e10cSrcweir                     ::rtl::OUString sCatalog, sSchema, sTable;
558cdf0e10cSrcweir 	                qualifiedNameComponents( xMeta, m_aListSource, sCatalog, sSchema, sTable, eInDataManipulation );
559cdf0e10cSrcweir 
560cdf0e10cSrcweir                     ::rtl::OUStringBuffer aStatement;
561cdf0e10cSrcweir                     aStatement.appendAscii( "SELECT DISTINCT " );
562cdf0e10cSrcweir                     aStatement.append     ( quoteName( aQuote, aFieldName ) );
563cdf0e10cSrcweir                     aStatement.appendAscii( " FROM " );
564cdf0e10cSrcweir                     aStatement.append     ( composeTableNameForSelect( xConnection, sCatalog, sSchema, sTable ) );
565cdf0e10cSrcweir 
566cdf0e10cSrcweir                     m_aListRowSet.setEscapeProcessing( sal_False );
567cdf0e10cSrcweir                     m_aListRowSet.setCommand( aStatement.makeStringAndClear() );
568cdf0e10cSrcweir                     bExecuteRowSet = true;
569cdf0e10cSrcweir 				}
570cdf0e10cSrcweir 			}	break;
571cdf0e10cSrcweir 			case ListSourceType_QUERY:
572cdf0e10cSrcweir 			{
573cdf0e10cSrcweir                 m_aListRowSet.setCommandFromQuery( m_aListSource );
574cdf0e10cSrcweir                 bExecuteRowSet = true;
575cdf0e10cSrcweir 			}
576cdf0e10cSrcweir             break;
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 			default:
579cdf0e10cSrcweir 			{
580cdf0e10cSrcweir                 m_aListRowSet.setEscapeProcessing( ListSourceType_SQLPASSTHROUGH != m_eListSourceType );
581cdf0e10cSrcweir                 m_aListRowSet.setCommand( m_aListSource );
582cdf0e10cSrcweir                 bExecuteRowSet = true;
583cdf0e10cSrcweir 			}
584cdf0e10cSrcweir 		}
585cdf0e10cSrcweir 
586cdf0e10cSrcweir         if ( bExecuteRowSet )
587cdf0e10cSrcweir         {
588cdf0e10cSrcweir             if ( !_bForce && !m_aListRowSet.isDirty() )
589cdf0e10cSrcweir             {
590cdf0e10cSrcweir                 // if none of the settings of the row set changed, compared to the last
591cdf0e10cSrcweir                 // invocation of loadData, then don't re-fill the list. Instead, assume
592cdf0e10cSrcweir                 // the list entries are the same.
593cdf0e10cSrcweir                 return;
594cdf0e10cSrcweir             }
595cdf0e10cSrcweir             xListCursor.reset( m_aListRowSet.execute() );
596cdf0e10cSrcweir         }
597cdf0e10cSrcweir 	}
598cdf0e10cSrcweir 	catch(SQLException& eSQL)
599cdf0e10cSrcweir 	{
600cdf0e10cSrcweir 		onError(eSQL, FRM_RES_STRING(RID_BASELISTBOX_ERROR_FILLLIST));
601cdf0e10cSrcweir 		return;
602cdf0e10cSrcweir 	}
603cdf0e10cSrcweir 	catch( const Exception& )
604cdf0e10cSrcweir 	{
605cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
606cdf0e10cSrcweir 		return;
607cdf0e10cSrcweir 	}
608cdf0e10cSrcweir 
609cdf0e10cSrcweir 	::std::vector< ::rtl::OUString >	aStringList;
610cdf0e10cSrcweir 	aStringList.reserve(16);
611cdf0e10cSrcweir 	try
612cdf0e10cSrcweir 	{
613cdf0e10cSrcweir         OSL_ENSURE( xListCursor.is() || ( ListSourceType_TABLEFIELDS == m_eListSourceType ),
614cdf0e10cSrcweir             "OComboBoxModel::loadData: logic error!" );
615cdf0e10cSrcweir         if ( !xListCursor.is() && ( ListSourceType_TABLEFIELDS != m_eListSourceType ) )
616cdf0e10cSrcweir 		    return;
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 		switch (m_eListSourceType)
619cdf0e10cSrcweir 		{
620cdf0e10cSrcweir 			case ListSourceType_SQL:
621cdf0e10cSrcweir 			case ListSourceType_SQLPASSTHROUGH:
622cdf0e10cSrcweir 			case ListSourceType_TABLE:
623cdf0e10cSrcweir 			case ListSourceType_QUERY:
624cdf0e10cSrcweir 			{
625cdf0e10cSrcweir 				// die XDatabaseVAriant der ersten Spalte
626cdf0e10cSrcweir 				Reference<XColumnsSupplier> xSupplyCols(xListCursor, UNO_QUERY);
627cdf0e10cSrcweir 				DBG_ASSERT(xSupplyCols.is(), "OComboBoxModel::loadData : cursor supports the row set service but is no column supplier?!");
628cdf0e10cSrcweir 				Reference<XIndexAccess> xColumns;
629cdf0e10cSrcweir 				if (xSupplyCols.is())
630cdf0e10cSrcweir 				{
631cdf0e10cSrcweir 					xColumns = Reference<XIndexAccess>(xSupplyCols->getColumns(), UNO_QUERY);
632cdf0e10cSrcweir 					DBG_ASSERT(xColumns.is(), "OComboBoxModel::loadData : no columns supplied by the row set !");
633cdf0e10cSrcweir 				}
634cdf0e10cSrcweir 				Reference< XPropertySet > xDataField;
635cdf0e10cSrcweir 				if ( xColumns.is() )
636cdf0e10cSrcweir 					xColumns->getByIndex(0) >>= xDataField;
637cdf0e10cSrcweir 				if ( !xDataField.is() )
638cdf0e10cSrcweir 					return;
639cdf0e10cSrcweir 
640cdf0e10cSrcweir                 ::dbtools::FormattedColumnValue aValueFormatter( getContext(), xForm, xDataField );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir 				// Listen fuellen
643cdf0e10cSrcweir 				sal_Int16 i = 0;
644cdf0e10cSrcweir 				// per definitionem the list cursor is positioned _before_ the first row at the moment
645cdf0e10cSrcweir 				while (xListCursor->next() && (i++<SHRT_MAX)) // max anzahl eintraege
646cdf0e10cSrcweir 				{
647cdf0e10cSrcweir                     aStringList.push_back( aValueFormatter.getFormattedValue() );
648cdf0e10cSrcweir 				}
649cdf0e10cSrcweir 			}
650cdf0e10cSrcweir 			break;
651cdf0e10cSrcweir 			case ListSourceType_TABLEFIELDS:
652cdf0e10cSrcweir 			{
653cdf0e10cSrcweir 				Reference<XNameAccess> xFieldNames = getTableFields(xConnection, m_aListSource);
654cdf0e10cSrcweir 				if (xFieldNames.is())
655cdf0e10cSrcweir 				{
656cdf0e10cSrcweir 					StringSequence seqNames = xFieldNames->getElementNames();
657cdf0e10cSrcweir 					sal_Int32 nFieldsCount = seqNames.getLength();
658cdf0e10cSrcweir 					const ::rtl::OUString* pustrNames = seqNames.getConstArray();
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 					for (sal_Int32 k=0; k<nFieldsCount; ++k)
661cdf0e10cSrcweir 						aStringList.push_back(pustrNames[k]);
662cdf0e10cSrcweir 				}
663cdf0e10cSrcweir 			}
664cdf0e10cSrcweir 			break;
665cdf0e10cSrcweir             default:
666cdf0e10cSrcweir                 OSL_ENSURE( false, "OComboBoxModel::loadData: unreachable!" );
667cdf0e10cSrcweir                 break;
668cdf0e10cSrcweir 		}
669cdf0e10cSrcweir 	}
670cdf0e10cSrcweir 	catch(SQLException& eSQL)
671cdf0e10cSrcweir 	{
672cdf0e10cSrcweir 		onError(eSQL, FRM_RES_STRING(RID_BASELISTBOX_ERROR_FILLLIST));
673cdf0e10cSrcweir 		return;
674cdf0e10cSrcweir 	}
675cdf0e10cSrcweir 	catch( const Exception& )
676cdf0e10cSrcweir 	{
677cdf0e10cSrcweir 		DBG_UNHANDLED_EXCEPTION();
678cdf0e10cSrcweir 		return;
679cdf0e10cSrcweir 	}
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 		// String-Sequence fuer ListBox erzeugen
682cdf0e10cSrcweir 	StringSequence aStringSeq(aStringList.size());
683cdf0e10cSrcweir 	::rtl::OUString* pStringAry = aStringSeq.getArray();
684cdf0e10cSrcweir 	for (sal_Int32 i = 0; i<aStringSeq.getLength(); ++i)
685cdf0e10cSrcweir 		pStringAry[i] = aStringList[i];
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 	// String-Sequence an ListBox setzen
688cdf0e10cSrcweir 	setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( aStringSeq ) );
689cdf0e10cSrcweir }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir //------------------------------------------------------------------------------
onConnectedDbColumn(const Reference<XInterface> & _rxForm)692cdf0e10cSrcweir void OComboBoxModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir 	Reference<XPropertySet> xField = getField();
695cdf0e10cSrcweir 	if ( xField.is() )
696cdf0e10cSrcweir         m_pValueFormatter.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
697cdf0e10cSrcweir     getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= m_aDesignModeStringItems;
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 	// Daten nur laden, wenn eine Listenquelle angegeben wurde
700cdf0e10cSrcweir 	if ( m_aListSource.getLength() && m_xCursor.is() && !hasExternalListSource() )
701cdf0e10cSrcweir 		loadData( false );
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir //------------------------------------------------------------------------------
onDisconnectedDbColumn()705cdf0e10cSrcweir void OComboBoxModel::onDisconnectedDbColumn()
706cdf0e10cSrcweir {
707cdf0e10cSrcweir     m_pValueFormatter.reset();
708cdf0e10cSrcweir 
709cdf0e10cSrcweir 	// reset the string item list
710cdf0e10cSrcweir     if ( !hasExternalListSource() )
711cdf0e10cSrcweir         setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( m_aDesignModeStringItems ) );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir     m_aListRowSet.dispose();
714cdf0e10cSrcweir }
715cdf0e10cSrcweir 
716cdf0e10cSrcweir //------------------------------------------------------------------------------
reloaded(const EventObject & aEvent)717cdf0e10cSrcweir void SAL_CALL OComboBoxModel::reloaded( const EventObject& aEvent ) throw(RuntimeException)
718cdf0e10cSrcweir {
719cdf0e10cSrcweir 	OBoundControlModel::reloaded(aEvent);
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 	// reload data if we have a list source
722cdf0e10cSrcweir 	if ( m_aListSource.getLength() && m_xCursor.is() && !hasExternalListSource() )
723cdf0e10cSrcweir 		loadData( false );
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
726cdf0e10cSrcweir //------------------------------------------------------------------------------
resetNoBroadcast()727cdf0e10cSrcweir void OComboBoxModel::resetNoBroadcast()
728cdf0e10cSrcweir {
729cdf0e10cSrcweir     OBoundControlModel::resetNoBroadcast();
730cdf0e10cSrcweir     m_aLastKnownValue.clear();
731cdf0e10cSrcweir }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir //-----------------------------------------------------------------------------
commitControlValueToDbColumn(bool _bPostReset)734cdf0e10cSrcweir sal_Bool OComboBoxModel::commitControlValueToDbColumn( bool _bPostReset )
735cdf0e10cSrcweir {
736cdf0e10cSrcweir     Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir     ::rtl::OUString sNewValue;
739cdf0e10cSrcweir     aNewValue >>= sNewValue;
740cdf0e10cSrcweir 
741cdf0e10cSrcweir     bool bModified = ( aNewValue != m_aLastKnownValue );
742cdf0e10cSrcweir     if ( bModified )
743cdf0e10cSrcweir 	{
744cdf0e10cSrcweir 		if  (   !aNewValue.hasValue()
745cdf0e10cSrcweir             ||  (   !sNewValue.getLength()      // an empty string
746cdf0e10cSrcweir                 &&  m_bEmptyIsNull              // which should be interpreted as NULL
747cdf0e10cSrcweir                 )
748cdf0e10cSrcweir             )
749cdf0e10cSrcweir         {
750cdf0e10cSrcweir 			m_xColumnUpdate->updateNull();
751cdf0e10cSrcweir         }
752cdf0e10cSrcweir 		else
753cdf0e10cSrcweir 		{
754cdf0e10cSrcweir 			try
755cdf0e10cSrcweir 			{
756cdf0e10cSrcweir                 OSL_PRECOND( m_pValueFormatter.get(), "OComboBoxModel::commitControlValueToDbColumn: no value formatter!" );
757cdf0e10cSrcweir                 if ( m_pValueFormatter.get() )
758cdf0e10cSrcweir                 {
759cdf0e10cSrcweir                     if ( !m_pValueFormatter->setFormattedValue( sNewValue ) )
760cdf0e10cSrcweir                         return sal_False;
761cdf0e10cSrcweir                 }
762cdf0e10cSrcweir 				else
763cdf0e10cSrcweir 					m_xColumnUpdate->updateString( sNewValue );
764cdf0e10cSrcweir 			}
765cdf0e10cSrcweir 			catch ( const Exception& )
766cdf0e10cSrcweir 			{
767cdf0e10cSrcweir 				return sal_False;
768cdf0e10cSrcweir 			}
769cdf0e10cSrcweir 		}
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 		m_aLastKnownValue = aNewValue;
772cdf0e10cSrcweir 	}
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 	// add the new value to the list
775cdf0e10cSrcweir 	sal_Bool bAddToList = bModified && !_bPostReset;
776cdf0e10cSrcweir     	// (only if this is not the "commit" triggered by a "reset")
777cdf0e10cSrcweir 
778cdf0e10cSrcweir     if ( bAddToList )
779cdf0e10cSrcweir     {
780cdf0e10cSrcweir         StringSequence aStringItemList;
781cdf0e10cSrcweir         if ( getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aStringItemList )
782cdf0e10cSrcweir 	    {
783cdf0e10cSrcweir 		    const ::rtl::OUString* pStringItems = aStringItemList.getConstArray();
784cdf0e10cSrcweir 		    sal_Int32 i;
785cdf0e10cSrcweir 		    for (i=0; i<aStringItemList.getLength(); ++i, ++pStringItems)
786cdf0e10cSrcweir 		    {
787cdf0e10cSrcweir 			    if ( pStringItems->equals( sNewValue ) )
788cdf0e10cSrcweir 				    break;
789cdf0e10cSrcweir 		    }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 		    // not found -> add
792cdf0e10cSrcweir 		    if (i >= aStringItemList.getLength())
793cdf0e10cSrcweir 		    {
794cdf0e10cSrcweir 			    sal_Int32 nOldLen = aStringItemList.getLength();
795cdf0e10cSrcweir 			    aStringItemList.realloc( nOldLen + 1 );
796cdf0e10cSrcweir 			    aStringItemList.getArray()[ nOldLen ] = sNewValue;
797cdf0e10cSrcweir 
798cdf0e10cSrcweir                 setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( aStringItemList ) );
799cdf0e10cSrcweir 		    }
800cdf0e10cSrcweir         }
801cdf0e10cSrcweir 	}
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 	return sal_True;
804cdf0e10cSrcweir }
805cdf0e10cSrcweir 
806cdf0e10cSrcweir // XPropertiesChangeListener
807cdf0e10cSrcweir //------------------------------------------------------------------------------
translateDbColumnToControlValue()808cdf0e10cSrcweir Any OComboBoxModel::translateDbColumnToControlValue()
809cdf0e10cSrcweir {
810cdf0e10cSrcweir     OSL_PRECOND( m_pValueFormatter.get(), "OComboBoxModel::translateDbColumnToControlValue: no value formatter!" );
811cdf0e10cSrcweir     if ( m_pValueFormatter.get() )
812cdf0e10cSrcweir     {
813cdf0e10cSrcweir         ::rtl::OUString sValue( m_pValueFormatter->getFormattedValue() );
814cdf0e10cSrcweir         if  (   !sValue.getLength()
815cdf0e10cSrcweir             &&  m_pValueFormatter->getColumn().is()
816cdf0e10cSrcweir             &&  m_pValueFormatter->getColumn()->wasNull()
817cdf0e10cSrcweir             )
818cdf0e10cSrcweir         {
819cdf0e10cSrcweir             m_aLastKnownValue.clear();
820cdf0e10cSrcweir         }
821cdf0e10cSrcweir         else
822cdf0e10cSrcweir         {
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 	        m_aLastKnownValue <<= sValue;
825cdf0e10cSrcweir         }
826cdf0e10cSrcweir     }
827cdf0e10cSrcweir     else
828cdf0e10cSrcweir         m_aLastKnownValue.clear();
829cdf0e10cSrcweir 
830cdf0e10cSrcweir     return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( ::rtl::OUString() );
831cdf0e10cSrcweir         // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
832cdf0e10cSrcweir }
833cdf0e10cSrcweir 
834cdf0e10cSrcweir //------------------------------------------------------------------------------
getDefaultForReset() const835cdf0e10cSrcweir Any OComboBoxModel::getDefaultForReset() const
836cdf0e10cSrcweir {
837cdf0e10cSrcweir     return makeAny( m_aDefaultText );
838cdf0e10cSrcweir }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir //--------------------------------------------------------------------
stringItemListChanged(ControlModelLock &)841cdf0e10cSrcweir void OComboBoxModel::stringItemListChanged( ControlModelLock& /*_rInstanceLock*/ )
842cdf0e10cSrcweir {
843cdf0e10cSrcweir     if ( m_xAggregateSet.is() )
844cdf0e10cSrcweir         m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( getStringItemList() ) );
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir //--------------------------------------------------------------------
connectedExternalListSource()848cdf0e10cSrcweir void OComboBoxModel::connectedExternalListSource( )
849cdf0e10cSrcweir {
850cdf0e10cSrcweir     // TODO?
851cdf0e10cSrcweir }
852cdf0e10cSrcweir 
853cdf0e10cSrcweir //--------------------------------------------------------------------
disconnectedExternalListSource()854cdf0e10cSrcweir void OComboBoxModel::disconnectedExternalListSource( )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir     // TODO?
857cdf0e10cSrcweir }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir //--------------------------------------------------------------------
refreshInternalEntryList()860cdf0e10cSrcweir void OComboBoxModel::refreshInternalEntryList()
861cdf0e10cSrcweir {
862cdf0e10cSrcweir     DBG_ASSERT( !hasExternalListSource(), "OComboBoxModel::refreshInternalEntryList: invalid call!" );
863cdf0e10cSrcweir 
864cdf0e10cSrcweir     if  (   !hasExternalListSource( )
865cdf0e10cSrcweir         &&  ( m_eListSourceType != ListSourceType_VALUELIST )
866cdf0e10cSrcweir         &&  ( m_xCursor.is() )
867cdf0e10cSrcweir         )
868cdf0e10cSrcweir     {
869cdf0e10cSrcweir         loadData( true );
870cdf0e10cSrcweir     }
871cdf0e10cSrcweir }
872cdf0e10cSrcweir 
873cdf0e10cSrcweir //--------------------------------------------------------------------
disposing(const EventObject & _rSource)874cdf0e10cSrcweir void SAL_CALL OComboBoxModel::disposing( const EventObject& _rSource ) throw ( RuntimeException )
875cdf0e10cSrcweir {
876cdf0e10cSrcweir     if ( !OEntryListHelper::handleDisposing( _rSource ) )
877cdf0e10cSrcweir         OBoundControlModel::disposing( _rSource );
878cdf0e10cSrcweir }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir //========================================================================
881cdf0e10cSrcweir //= OComboBoxControl
882cdf0e10cSrcweir //========================================================================
883cdf0e10cSrcweir 
884cdf0e10cSrcweir //------------------------------------------------------------------
OComboBoxControl_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)885cdf0e10cSrcweir InterfaceRef SAL_CALL OComboBoxControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
886cdf0e10cSrcweir {
887cdf0e10cSrcweir 	return *(new OComboBoxControl(_rxFactory));
888cdf0e10cSrcweir }
889cdf0e10cSrcweir 
890cdf0e10cSrcweir //------------------------------------------------------------------------------
OComboBoxControl(const Reference<XMultiServiceFactory> & _rxFactory)891cdf0e10cSrcweir OComboBoxControl::OComboBoxControl(const Reference<XMultiServiceFactory>& _rxFactory)
892cdf0e10cSrcweir 	:OBoundControl(_rxFactory, VCL_CONTROL_COMBOBOX)
893cdf0e10cSrcweir {
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames()897cdf0e10cSrcweir StringSequence SAL_CALL OComboBoxControl::getSupportedServiceNames() throw(RuntimeException)
898cdf0e10cSrcweir {
899cdf0e10cSrcweir 	StringSequence aSupported = OBoundControl::getSupportedServiceNames();
900cdf0e10cSrcweir 	aSupported.realloc(aSupported.getLength() + 1);
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 	::rtl::OUString* pArray = aSupported.getArray();
903cdf0e10cSrcweir 	pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_COMBOBOX;
904cdf0e10cSrcweir 	return aSupported;
905cdf0e10cSrcweir }
906cdf0e10cSrcweir 
907cdf0e10cSrcweir //.........................................................................
908cdf0e10cSrcweir }
909cdf0e10cSrcweir //.........................................................................
910cdf0e10cSrcweir 
911