diff options
author | Eike Rathke <erack@redhat.com> | 2017-02-10 18:27:14 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-02-10 20:58:52 +0100 |
commit | e387b69967aabc44d5da5aaad8d94191437dc57c (patch) | |
tree | 03d090da3436b466037ea5f7f83593150325d931 /forms/source | |
parent | bed701f31a4668a80f6e447c18a3db08cb43de82 (diff) |
Resolves: tdf#79250 add typed list to form control listbox
... so numeric and text data can be distinguished input.
Change-Id: I63280a93c272ccc6f5e7ca06a1a1fcbfb3db8455
Diffstat (limited to 'forms/source')
-rw-r--r-- | forms/source/component/ComboBox.cxx | 17 | ||||
-rw-r--r-- | forms/source/component/ListBox.cxx | 47 | ||||
-rw-r--r-- | forms/source/component/entrylisthelper.cxx | 54 | ||||
-rw-r--r-- | forms/source/component/entrylisthelper.hxx | 13 | ||||
-rw-r--r-- | forms/source/inc/frm_strings.hxx | 1 | ||||
-rw-r--r-- | forms/source/inc/property.hrc | 2 |
6 files changed, 126 insertions, 8 deletions
diff --git a/forms/source/component/ComboBox.cxx b/forms/source/component/ComboBox.cxx index 57ff1e6b2122..dd419a171ff4 100644 --- a/forms/source/component/ComboBox.cxx +++ b/forms/source/component/ComboBox.cxx @@ -193,6 +193,10 @@ void OComboBoxModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) cons _rValue <<= comphelper::containerToSequence(getStringItemList()); break; + case PROPERTY_ID_TYPEDITEMLIST: + _rValue <<= getTypedItemList(); + break; + default: OBoundControlModel::getFastPropertyValue(_rValue, _nHandle); } @@ -247,6 +251,11 @@ void OComboBoxModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const } break; + // XXX NOTE: PROPERTY_ID_TYPEDITEMLIST not handled here because only + // set for external sources in which case not even + // setNewStringItemList() for PROPERTY_ID_STRINGITEMLIST above should + // had been called ... + default: OBoundControlModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue); } @@ -304,6 +313,7 @@ void OComboBoxModel::describeAggregateProperties( Sequence< Property >& _rAggreg // superseded properties: RemoveProperty( _rAggregateProps, PROPERTY_STRINGITEMLIST ); + RemoveProperty( _rAggregateProps, PROPERTY_TYPEDITEMLIST ); } @@ -432,6 +442,7 @@ void SAL_CALL OComboBoxModel::read(const Reference<css::io::XObjectInputStream>& ) { setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( css::uno::Sequence<OUString>() ) ); + setFastPropertyValue( PROPERTY_ID_TYPEDITEMLIST, makeAny( css::uno::Sequence<css::uno::Any>() ) ); } if (nVersion > 0x0004) @@ -655,6 +666,8 @@ void OComboBoxModel::loadData( bool _bForce ) // Set String-Sequence at ListBox setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( comphelper::containerToSequence(aStringList) ) ); + // Reset TypedItemList, no matching data. + setFastPropertyValue( PROPERTY_ID_TYPEDITEMLIST, makeAny( css::uno::Sequence<css::uno::Any>() ) ); } @@ -765,6 +778,7 @@ bool OComboBoxModel::commitControlValueToDbColumn( bool _bPostReset ) aStringItemList.getArray()[ nOldLen ] = sNewValue; setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( aStringItemList ) ); + setFastPropertyValue( PROPERTY_ID_TYPEDITEMLIST, makeAny( css::uno::Sequence<css::uno::Any>() ) ); } } } @@ -810,7 +824,10 @@ Any OComboBoxModel::getDefaultForReset() const void OComboBoxModel::stringItemListChanged( ControlModelLock& /*_rInstanceLock*/ ) { if ( m_xAggregateSet.is() ) + { m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( comphelper::containerToSequence(getStringItemList()) ) ); + m_xAggregateSet->setPropertyValue( PROPERTY_TYPEDITEMLIST, makeAny( getTypedItemList()) ) ; + } } diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx index 2b5426f23a6c..5fd3e9b96a0f 100644 --- a/forms/source/component/ListBox.cxx +++ b/forms/source/component/ListBox.cxx @@ -147,6 +147,7 @@ namespace frm void OListBoxModel::init() { startAggregatePropertyListening( PROPERTY_STRINGITEMLIST ); + startAggregatePropertyListening( PROPERTY_TYPEDITEMLIST ); } @@ -286,6 +287,10 @@ namespace frm _rValue <<= comphelper::containerToSequence(getStringItemList()); break; + case PROPERTY_ID_TYPEDITEMLIST: + _rValue <<= getTypedItemList(); + break; + default: OBoundControlModel::getFastPropertyValue(_rValue, _nHandle); } @@ -382,6 +387,10 @@ namespace frm resetNoBroadcast(); break; + case PROPERTY_ID_TYPEDITEMLIST: + /* TODO: anything? */ + break; + default: OBoundControlModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue); } @@ -434,6 +443,10 @@ namespace frm bModified = convertNewListSourceProperty( _rConvertedValue, _rOldValue, _rValue ); break; + case PROPERTY_ID_TYPEDITEMLIST: + /* TODO: anything? */ + break; + default: return OBoundControlModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue); } @@ -505,6 +518,7 @@ namespace frm // <----- SYNCHRONIZED return; } + // XXX NOTE: PROPERTY_TYPEDITEMLIST not handled, used only with external list source. OBoundControlModel::_propertyChanged( i_rEvent ); } @@ -515,6 +529,7 @@ namespace frm // superseded properties: RemoveProperty( _rAggregateProps, PROPERTY_STRINGITEMLIST ); + RemoveProperty( _rAggregateProps, PROPERTY_TYPEDITEMLIST ); } @@ -669,6 +684,7 @@ namespace frm ) { setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( css::uno::Sequence<OUString>() ) ); + setFastPropertyValue( PROPERTY_ID_TYPEDITEMLIST, makeAny( css::uno::Sequence<css::uno::Any>() ) ); } if (nVersion > 3) @@ -991,6 +1007,7 @@ namespace frm setBoundValues(aValueList); setFastPropertyValue( PROPERTY_ID_STRINGITEMLIST, makeAny( lcl_convertToStringSequence( aDisplayList ) ) ); + setFastPropertyValue( PROPERTY_ID_TYPEDITEMLIST, makeAny( css::uno::Sequence<css::uno::Any>() ) ); } @@ -1456,6 +1473,26 @@ namespace frm }; + Any lcl_getSingleSelectedEntryTyped( const Sequence< sal_Int16 >& _rSelectSequence, const Sequence<Any>& _rTypedList ) + { + Any aReturn; + + // by definition, multiple selected entries are transferred as NULL if the + // binding does not support lists + if ( _rSelectSequence.getLength() <= 1 ) + { + if ( _rSelectSequence.getLength() == 1 ) + { + sal_Int32 nIndex = _rSelectSequence[0]; + if (0 <= nIndex && nIndex < _rTypedList.getLength()) + aReturn = _rTypedList[nIndex]; + } + } + + return aReturn; + } + + Any lcl_getSingleSelectedEntry( const Sequence< sal_Int16 >& _rSelectSequence, const std::vector< OUString >& _rStringList ) { Any aReturn; @@ -1586,7 +1623,14 @@ namespace frm break; case eEntry: - aReturn = lcl_getSingleSelectedEntry( aSelectSequence, getStringItemList() ); + { + const std::vector<OUString>& rStrings = getStringItemList(); + const Sequence<Any>& rValues = getTypedItemList(); + if (rStrings.size() == static_cast<size_t>(rValues.getLength())) + aReturn = lcl_getSingleSelectedEntryTyped( aSelectSequence, rValues ); + else + aReturn = lcl_getSingleSelectedEntry( aSelectSequence, rStrings ); + } break; } @@ -1689,6 +1733,7 @@ namespace frm try { m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( comphelper::containerToSequence(getStringItemList()) ) ); + m_xAggregateSet->setPropertyValue( PROPERTY_TYPEDITEMLIST, makeAny( getTypedItemList() ) ); } catch( const Exception& ) { diff --git a/forms/source/component/entrylisthelper.cxx b/forms/source/component/entrylisthelper.cxx index b306256463f9..4e9202be73da 100644 --- a/forms/source/component/entrylisthelper.cxx +++ b/forms/source/component/entrylisthelper.cxx @@ -23,6 +23,7 @@ #include <osl/diagnose.h> #include <comphelper/sequence.hxx> #include <comphelper/property.hxx> +#include <com/sun/star/form/binding/XListEntryTypedSource.hpp> #include <algorithm> @@ -92,6 +93,8 @@ namespace frm ) { m_aStringItems[ _rEvent.Position ] = _rEvent.Entries[ 0 ]; + if (m_aTypedItems.getLength()) + m_aTypedItems = Sequence<Any>(); // doesn't match anymore stringItemListChanged( aLock ); } } @@ -112,7 +115,8 @@ namespace frm ) { m_aStringItems.insert(m_aStringItems.begin() + _rEvent.Position, _rEvent.Entries.begin(), _rEvent.Entries.end()); - + if (m_aTypedItems.getLength()) + m_aTypedItems = Sequence<Any>(); // doesn't match anymore stringItemListChanged( aLock ); } } @@ -134,6 +138,26 @@ namespace frm { m_aStringItems.erase(m_aStringItems.begin() + _rEvent.Position, m_aStringItems.begin() + _rEvent.Position + _rEvent.Count ); + if (_rEvent.Position + _rEvent.Count <= m_aTypedItems.getLength()) + { + Sequence<Any> aTmp( m_aTypedItems.getLength() - _rEvent.Count ); + sal_Int32 nStop = _rEvent.Position; + sal_Int32 i = 0; + for ( ; i < nStop; ++i) + { + aTmp[i] = m_aTypedItems[i]; + } + nStop = aTmp.getLength(); + for (sal_Int32 j = _rEvent.Position + _rEvent.Count; i < nStop; ++i, ++j) + { + aTmp[i] = m_aTypedItems[j]; + } + m_aTypedItems = aTmp; + } + else if (m_aTypedItems.getLength()) + { + m_aTypedItems = Sequence<Any>(); // doesn't match anymore + } stringItemListChanged( aLock ); } } @@ -184,10 +208,7 @@ namespace frm void OEntryListHelper::impl_lock_refreshList( ControlModelLock& _rInstanceLock ) { if ( hasExternalListSource() ) - { - comphelper::sequenceToContainer(m_aStringItems, m_xListSource->getAllListEntries()); - stringItemListChanged( _rInstanceLock ); - } + obtainListSourceEntries( _rInstanceLock ); else refreshInternalEntryList(); } @@ -251,8 +272,7 @@ namespace frm // be notified when the list changes ... m_xListSource->addListEntryListener( this ); - comphelper::sequenceToContainer( m_aStringItems, m_xListSource->getAllListEntries() ); - stringItemListChanged( _rInstanceLock ); + obtainListSourceEntries( _rInstanceLock ); // let derivees react on the new list source connectedExternalListSource(); @@ -260,6 +280,24 @@ namespace frm } + void OEntryListHelper::obtainListSourceEntries( ControlModelLock& _rInstanceLock ) + { + Reference< XListEntryTypedSource > xTyped; + xTyped.set( m_xListSource, UNO_QUERY); + if (xTyped.is()) + { + comphelper::sequenceToContainer( m_aStringItems, xTyped->getAllListEntriesTyped( m_aTypedItems)); + } + else + { + comphelper::sequenceToContainer( m_aStringItems, m_xListSource->getAllListEntries()); + if (m_aTypedItems.getLength()) + m_aTypedItems = Sequence<Any>(); + } + stringItemListChanged( _rInstanceLock ); + } + + bool OEntryListHelper::convertNewListSourceProperty( Any& _rConvertedValue, Any& _rOldValue, const Any& _rValue ) { @@ -277,6 +315,8 @@ namespace frm css::uno::Sequence<OUString> aTmp; OSL_VERIFY( _rValue >>= aTmp ); comphelper::sequenceToContainer(m_aStringItems, aTmp); + if (m_aTypedItems.getLength()) + m_aTypedItems = Sequence<Any>(); // doesn't match anymore stringItemListChanged( _rInstanceLock ); } diff --git a/forms/source/component/entrylisthelper.hxx b/forms/source/component/entrylisthelper.hxx index 3ae722c92e3e..3ad407c6fea7 100644 --- a/forms/source/component/entrylisthelper.hxx +++ b/forms/source/component/entrylisthelper.hxx @@ -53,6 +53,8 @@ namespace frm m_xListSource; /// our external list source std::vector< OUString > m_aStringItems; /// "overridden" StringItemList property value + css::uno::Sequence< css::uno::Any > + m_aTypedItems; /// "overridden" TypedItemList property value ::comphelper::OInterfaceContainerHelper2 m_aRefreshListeners; @@ -66,6 +68,10 @@ namespace frm inline const std::vector< OUString >& getStringItemList() const { return m_aStringItems; } + /// returns the current typed item list + inline const css::uno::Sequence< css::uno::Any >& + getTypedItemList() const { return m_aTypedItems; } + /// determines whether we actually have an external list source inline bool hasExternalListSource( ) const { return m_xListSource.is(); } @@ -161,6 +167,13 @@ namespace frm ControlModelLock& _rInstanceLock ); + /** obtains list entries and possibly data values from list source + + @precond + m_xListSource has to hold an external list source + */ + void obtainListSourceEntries( ControlModelLock& _rInstanceLock ); + /** refreshes our list entries In case we have an external list source, its used to obtain the new entries, and then diff --git a/forms/source/inc/frm_strings.hxx b/forms/source/inc/frm_strings.hxx index 7415ebee90ea..868772abc744 100644 --- a/forms/source/inc/frm_strings.hxx +++ b/forms/source/inc/frm_strings.hxx @@ -70,6 +70,7 @@ namespace frm #define PROPERTY_HIDDEN_VALUE "HiddenValue" #define PROPERTY_BUTTONTYPE "ButtonType" #define PROPERTY_STRINGITEMLIST "StringItemList" + #define PROPERTY_TYPEDITEMLIST "TypedItemList" #define PROPERTY_DEFAULT_TEXT "DefaultText" #define PROPERTY_DEFAULT_STATE "DefaultState" #define PROPERTY_FORMATKEY "FormatKey" diff --git a/forms/source/inc/property.hrc b/forms/source/inc/property.hrc index 2086db0c94ed..57b6202d085e 100644 --- a/forms/source/inc/property.hrc +++ b/forms/source/inc/property.hrc @@ -292,6 +292,8 @@ namespace frm #define PROPERTY_ID_CONTROL_TYPE_IN_MSO ( PROPERTY_ID_START + 261 ) #define PROPERTY_ID_OBJ_ID_IN_MSO ( PROPERTY_ID_START + 262 ) +#define PROPERTY_ID_TYPEDITEMLIST ( PROPERTY_ID_START + 263 ) // Sequence<Any> + // start ID fuer aggregierte Properties #define PROPERTY_ID_AGGREGATE_ID (PROPERTY_ID_START + 10000) |