diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2015-01-13 14:56:23 +0100 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2015-01-13 14:59:04 +0100 |
commit | 0331fa6a904d3f923cb80d7104e74ea6f2958179 (patch) | |
tree | dab394fcd135a9e1071a3d024830864f30118f24 /forms | |
parent | 1cc29a04adb721205655091854f5ea828bb8eb11 (diff) |
ListBox with value list: consider first empty value as NULL
Change-Id: I15c040b481b7f03720d0227ba5d2fcd2ccc78386
Diffstat (limited to 'forms')
-rw-r--r-- | forms/source/component/ListBox.cxx | 34 | ||||
-rw-r--r-- | forms/source/component/ListBox.hxx | 5 |
2 files changed, 27 insertions, 12 deletions
diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx index d6eb7cf7860e..72ce58706548 100644 --- a/forms/source/component/ListBox.cxx +++ b/forms/source/component/ListBox.cxx @@ -79,6 +79,8 @@ namespace frm using ::connectivity::ORowSetValue; + const ::connectivity::ORowSetValue OListBoxModel::s_aEmptyValue; + const ::connectivity::ORowSetValue OListBoxModel::s_aEmptyStringValue = OUString(); //= helper @@ -1007,12 +1009,12 @@ namespace frm void OListBoxModel::onDisconnectedDbColumn() { + clearBoundValues(); + m_nNULLPos = -1; + m_nBoundColumnType = DataType::SQLNULL; + if ( m_eListSourceType != ListSourceType_VALUELIST ) { - clearBoundValues(); - m_nNULLPos = -1; - m_nBoundColumnType = DataType::SQLNULL; - if ( !hasExternalListSource() ) setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( StringSequence() ) ); @@ -1037,13 +1039,25 @@ namespace frm void OListBoxModel::convertBoundValues(const sal_Int32 nFieldType) const { + assert(s_aEmptyValue.isNull()); + m_nNULLPos = -1; m_aConvertedBoundValues.resize(m_aBoundValues.size()); ValueList::const_iterator src = m_aBoundValues.begin(); const ValueList::const_iterator end = m_aBoundValues.end(); ValueList::iterator dst = m_aConvertedBoundValues.begin(); for (; src != end; ++src, ++dst ) { - *dst = *src; + if(m_nNULLPos == -1 && + !isRequired() && + (*src == s_aEmptyStringValue || *src == s_aEmptyValue || src->isNull()) ) + { + m_nNULLPos = src - m_aBoundValues.begin(); + dst->setNull(); + } + else + { + *dst = *src; + } dst->setTypeKind(nFieldType); } m_nConvertedBoundValuesType = nFieldType; @@ -1090,21 +1104,19 @@ namespace frm ORowSetValue OListBoxModel::getFirstSelectedValue() const { - static const ORowSetValue s_aEmptyVaue; - DBG_ASSERT( m_xAggregateFastSet.is(), "OListBoxModel::getFirstSelectedValue: invalid aggregate!" ); if ( !m_xAggregateFastSet.is() ) - return s_aEmptyVaue; + return s_aEmptyValue; Sequence< sal_Int16 > aSelectedIndices; OSL_VERIFY( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) >>= aSelectedIndices ); if ( !aSelectedIndices.getLength() ) // nothing selected at all - return s_aEmptyVaue; + return s_aEmptyValue; if ( ( m_nNULLPos != -1 ) && ( aSelectedIndices[0] == m_nNULLPos ) ) // the dedicated "NULL" entry is selected - return s_aEmptyVaue; + return s_aEmptyValue; ValueList aValues( impl_getValues() ); @@ -1112,7 +1124,7 @@ namespace frm if ( selectedValue >= aValues.size() ) { SAL_WARN( "forms.component", "OListBoxModel::getFirstSelectedValue: inconsistent selection/valuelist!" ); - return s_aEmptyVaue; + return s_aEmptyValue; } return aValues[ selectedValue ]; diff --git a/forms/source/component/ListBox.hxx b/forms/source/component/ListBox.hxx index 85b380c497fb..a1217e875bc1 100644 --- a/forms/source/component/ListBox.hxx +++ b/forms/source/component/ListBox.hxx @@ -114,7 +114,7 @@ class OListBoxModel :public OBoundControlModel ::com::sun::star::uno::Sequence<sal_Int16> m_aDefaultSelectSeq; // DefaultSelected // </properties> - sal_Int16 m_nNULLPos; // position of the NULL value in our list + mutable sal_Int16 m_nNULLPos; // position of the NULL value in our list sal_Int32 m_nBoundColumnType; private: @@ -145,6 +145,9 @@ public: throw (::com::sun::star::lang::IllegalArgumentException) SAL_OVERRIDE; protected: + static const ::connectivity::ORowSetValue s_aEmptyValue; + static const ::connectivity::ORowSetValue s_aEmptyStringValue; + // XMultiPropertySet virtual void SAL_CALL setPropertyValues(const ::com::sun::star::uno::Sequence< OUString >& PropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; |