summaryrefslogtreecommitdiff
path: root/forms/source
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2012-02-16 13:24:58 +0100
committerPetr Mladek <pmladek@suse.cz>2012-02-21 12:52:02 +0100
commit10e26364d33150a1f43bcc32a690a9523d792936 (patch)
tree019f1d821bf04192107c5daf8f389bb531b951e1 /forms/source
parentb5f33bb8fa14afa17c4694d587215cab4756aa1f (diff)
fdo#46163 convert bound values to bound column's type
Signed-off-by: Petr Mladek <pmladek@suse.cz>
Diffstat (limited to 'forms/source')
-rw-r--r--forms/source/component/ListBox.cxx70
-rw-r--r--forms/source/component/ListBox.hxx11
2 files changed, 67 insertions, 14 deletions
diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx
index d982e50576fd..7d3b72bb3c8c 100644
--- a/forms/source/component/ListBox.cxx
+++ b/forms/source/component/ListBox.cxx
@@ -326,7 +326,7 @@ namespace frm
// propagate
if ( m_eListSourceType == ListSourceType_VALUELIST )
{
- m_aBoundValues = m_aListSourceValues;
+ setBoundValues(m_aListSourceValues);
}
else
{
@@ -556,7 +556,7 @@ namespace frm
OSL_FAIL("OListBoxModel::read : invalid (means unknown) version !");
ValueList().swap(m_aListSourceValues);
m_aBoundColumn <<= (sal_Int16)0;
- ValueList().swap(m_aBoundValues);
+ clearBoundValues();
m_eListSourceType = ListSourceType_VALUELIST;
m_aDefaultSelectSeq.realloc(0);
defaultCommonProperties();
@@ -674,7 +674,7 @@ namespace frm
// outta here if we don't have all pre-requisites
if ( !xConnection.is() || !sListSource.getLength() )
{
- ValueList().swap(m_aBoundValues);
+ clearBoundValues();
return;
}
@@ -925,7 +925,7 @@ namespace frm
m_nNULLPos = 0;
}
- m_aBoundValues = aValueList;
+ setBoundValues(aValueList);
setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( lcl_convertToStringSequence( aDisplayList ) ) );
}
@@ -949,7 +949,7 @@ namespace frm
{
if ( m_eListSourceType != ListSourceType_VALUELIST )
{
- ValueList().swap(m_aBoundValues);
+ clearBoundValues();
m_nNULLPos = -1;
m_nBoundColumnType = DataType::SQLNULL;
@@ -961,19 +961,63 @@ namespace frm
}
//------------------------------------------------------------------------------
+ void OListBoxModel::setBoundValues(const ValueList &l)
+ {
+ m_aConvertedBoundValues.clear();
+ m_aBoundValues = l;
+ }
+
+ //------------------------------------------------------------------------------
+ void OListBoxModel::clearBoundValues()
+ {
+ ValueList().swap(m_aConvertedBoundValues);
+ ValueList().swap(m_aBoundValues);
+ }
+
+ //------------------------------------------------------------------------------
+ void OListBoxModel::convertBoundValues(const sal_Int32 nFieldType) const
+ {
+ 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;
+ dst->setTypeKind(nFieldType);
+ }
+ m_nConvertedBoundValuesType = nFieldType;
+ OSL_ENSURE(dst == m_aConvertedBoundValues.end(), "OListBoxModel::convertBoundValues expected to have overwritten all of m_aConvertedBoundValues, but did not.");
+ }
+ //------------------------------------------------------------------------------
+ sal_Int32 OListBoxModel::getValueType() const
+ {
+ return impl_hasBoundComponent() ? m_nBoundColumnType : getFieldType();
+ }
+ //------------------------------------------------------------------------------
ValueList OListBoxModel::impl_getValues() const
{
+ const sal_Int32 nFieldType = getValueType();
+
+ if ( !m_aConvertedBoundValues.empty() && m_nConvertedBoundValuesType == nFieldType )
+ return m_aConvertedBoundValues;
+
if ( !m_aBoundValues.empty() )
- return m_aBoundValues;
+ {
+ convertBoundValues(nFieldType);
+ return m_aConvertedBoundValues;
+ }
Sequence< ::rtl::OUString > aStringItems( getStringItemList() );
ValueList aValues( aStringItems.getLength() );
- ::std::copy(
- aStringItems.getConstArray(),
- aStringItems.getConstArray() + aStringItems.getLength(),
- aValues.begin()
- );
-
+ ValueList::iterator dst = aValues.begin();
+ const ::rtl::OUString *src (aStringItems.getConstArray());
+ const ::rtl::OUString * const end = src + aStringItems.getLength();
+ for (; src < end; ++src, ++dst )
+ {
+ *dst = *src;
+ dst->setTypeKind(nFieldType);
+ }
return aValues;
}
//------------------------------------------------------------------------------
@@ -1046,7 +1090,7 @@ namespace frm
Sequence< sal_Int16 > aSelectionIndicies;
ORowSetValue aCurrentValue;
- aCurrentValue.fill( impl_hasBoundComponent() ? m_nBoundColumnType : getFieldType(), m_xColumn );
+ aCurrentValue.fill( getValueType(), m_xColumn );
// reset selection for NULL values
if ( aCurrentValue.isNull() )
diff --git a/forms/source/component/ListBox.hxx b/forms/source/component/ListBox.hxx
index cd1302c35fcc..d64a5a8053d2 100644
--- a/forms/source/component/ListBox.hxx
+++ b/forms/source/component/ListBox.hxx
@@ -79,7 +79,9 @@ class OListBoxModel :public OBoundControlModel
::com::sun::star::form::ListSourceType m_eListSourceType; // type der list source
::com::sun::star::uno::Any m_aBoundColumn;
ValueList m_aListSourceValues;
- ValueList m_aBoundValues;
+ ValueList m_aBoundValues; // do not write directly; use setBoundValues()
+ mutable ValueList m_aConvertedBoundValues;
+ mutable sal_Int32 m_nConvertedBoundValuesType;
::com::sun::star::uno::Sequence<sal_Int16> m_aDefaultSelectSeq; // DefaultSelected
// </properties>
@@ -181,8 +183,15 @@ private:
*/
void impl_refreshDbEntryList( bool _bForce );
+ void setBoundValues(const ValueList&);
+ void clearBoundValues();
+
ValueList impl_getValues() const;
+ sal_Int32 getValueType() const;
+
+ void convertBoundValues(sal_Int32 nType) const;
+
bool impl_hasBoundComponent() const { return m_nBoundColumnType != ::com::sun::star::sdbc::DataType::SQLNULL; }
};