diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2016-02-14 13:43:04 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-04-01 07:33:50 +0000 |
commit | 929eab216427d9f1c96df8b3ae9dafcad728e04e (patch) | |
tree | 26bb435d3d64bcc1219e88c0920ce990d47a8832 | |
parent | 3f7f497192deb486b1b959996c14f8f094146945 (diff) |
sequence->vector in forms
Change-Id: Iea09367a51af8d0003a3ae58f8e7e0e825906367
Reviewed-on: https://gerrit.libreoffice.org/23691
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r-- | forms/source/component/ComboBox.cxx | 4 | ||||
-rw-r--r-- | forms/source/component/FormComponent.cxx | 27 | ||||
-rw-r--r-- | forms/source/component/ListBox.cxx | 56 | ||||
-rw-r--r-- | forms/source/component/entrylisthelper.cxx | 51 | ||||
-rw-r--r-- | forms/source/component/entrylisthelper.hxx | 4 | ||||
-rw-r--r-- | forms/source/inc/FormComponent.hxx | 16 |
6 files changed, 77 insertions, 81 deletions
diff --git a/forms/source/component/ComboBox.cxx b/forms/source/component/ComboBox.cxx index 7103e54ea5cc..a3b04c7c339b 100644 --- a/forms/source/component/ComboBox.cxx +++ b/forms/source/component/ComboBox.cxx @@ -190,7 +190,7 @@ void OComboBoxModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) cons break; case PROPERTY_ID_STRINGITEMLIST: - _rValue <<= getStringItemList(); + _rValue <<= comphelper::containerToSequence(getStringItemList()); break; default: @@ -815,7 +815,7 @@ Any OComboBoxModel::getDefaultForReset() const void OComboBoxModel::stringItemListChanged( ControlModelLock& /*_rInstanceLock*/ ) { if ( m_xAggregateSet.is() ) - m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( getStringItemList() ) ); + m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( comphelper::containerToSequence(getStringItemList()) ) ); } diff --git a/forms/source/component/FormComponent.cxx b/forms/source/component/FormComponent.cxx index 4ffc3dd01745..e042c202c382 100644 --- a/forms/source/component/FormComponent.cxx +++ b/forms/source/component/FormComponent.cxx @@ -78,18 +78,11 @@ void ControlModelLock::impl_notifyAll_nothrow() void ControlModelLock::addPropertyNotification( const sal_Int32 _nHandle, const Any& _rOldValue, const Any& _rNewValue ) { - sal_Int32 nOldLength = m_aHandles.getLength(); - if ( ( nOldLength != m_aOldValues.getLength() ) - || ( nOldLength != m_aNewValues.getLength() ) - ) - throw RuntimeException( OUString(), m_rModel ); + assert( m_aHandles.size() == m_aOldValues.size() && m_aOldValues.size() == m_aNewValues.size() ); - m_aHandles.realloc( nOldLength + 1 ); - m_aHandles[ nOldLength ] = _nHandle; - m_aOldValues.realloc( nOldLength + 1 ); - m_aOldValues[ nOldLength ] = _rOldValue; - m_aNewValues.realloc( nOldLength + 1 ); - m_aNewValues[ nOldLength ] = _rNewValue; + m_aHandles.push_back( _nHandle ); + m_aOldValues.push_back( _rOldValue ); + m_aNewValues.push_back( _rNewValue ); } class FieldChangeNotifier @@ -1122,6 +1115,18 @@ void OControlModel::firePropertyChanges( const Sequence< sal_Int32 >& _rHandles, ); } +void OControlModel::firePropertyChanges( const std::vector< sal_Int32 >& _rHandles, const std::vector< Any >& _rOldValues, + const std::vector< Any >& _rNewValues, LockAccess ) +{ + OPropertySetHelper::fire( + const_cast< std::vector< sal_Int32 >& >( _rHandles ).data(), + _rNewValues.data(), + _rOldValues.data(), + _rHandles.size(), + sal_False + ); +} + // OBoundControlModel Any SAL_CALL OBoundControlModel::queryAggregation( const Type& _rType ) throw (RuntimeException, std::exception) { diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx index 2abf7a85cafa..b616fb77b412 100644 --- a/forms/source/component/ListBox.cxx +++ b/forms/source/component/ListBox.cxx @@ -282,7 +282,7 @@ namespace frm break; case PROPERTY_ID_STRINGITEMLIST: - _rValue <<= getStringItemList(); + _rValue <<= comphelper::containerToSequence(getStringItemList()); break; default: @@ -1077,12 +1077,12 @@ namespace frm return m_aConvertedBoundValues; } - Sequence< OUString > aStringItems( getStringItemList() ); - ValueList aValues( aStringItems.getLength() ); + const std::vector< OUString >& aStringItems( getStringItemList() ); + ValueList aValues( aStringItems.size() ); ValueList::iterator dst = aValues.begin(); - const OUString *src (aStringItems.getConstArray()); - const OUString * const end = src + aStringItems.getLength(); - for (; src < end; ++src, ++dst ) + std::vector< OUString >::const_iterator src(aStringItems.begin()); + std::vector< OUString >::const_iterator const end = aStringItems.end(); + for (; src != end; ++src, ++dst ) { *dst = *src; dst->setTypeKind(nFieldType); @@ -1369,7 +1369,7 @@ namespace frm { sal_Int32 nSelectIndex = -1; OSL_VERIFY( _rExternalValue >>= nSelectIndex ); - if ( ( nSelectIndex >= 0 ) && ( nSelectIndex < getStringItemList().getLength() ) ) + if ( ( nSelectIndex >= 0 ) && ( nSelectIndex < (sal_Int32)getStringItemList().size() ) ) { aSelectIndexes.realloc( 1 ); aSelectIndexes[ 0 ] = static_cast< sal_Int16 >( nSelectIndex ); @@ -1390,16 +1390,14 @@ namespace frm const OUString* pSelectEntriesEnd = pSelectEntries + aSelectEntries.getLength(); while ( pSelectEntries != pSelectEntriesEnd ) { - // the indexes where the current string appears in our string items - Sequence< sal_Int16 > aThisEntryIndexes; - aThisEntryIndexes = findValue( getStringItemList(), *pSelectEntries++ ); - - // insert all the indexes of this entry into our set - ::std::copy( - aThisEntryIndexes.getConstArray(), - aThisEntryIndexes.getConstArray() + aThisEntryIndexes.getLength(), - ::std::insert_iterator< ::std::set< sal_Int16 > >( aSelectionSet, aSelectionSet.begin() ) - ); + int idx = 0; + for(const OUString& s : getStringItemList()) + { + if (s==*pSelectEntries) + aSelectionSet.insert(idx); + ++idx; + } + ++pSelectEntries; } // copy the indexes to the sequence @@ -1411,8 +1409,16 @@ namespace frm { OUString sStringToSelect; OSL_VERIFY( _rExternalValue >>= sStringToSelect ); + ::std::set< sal_Int16 > aSelectionSet; + int idx = 0; + for(const OUString& s : getStringItemList()) + { + if (s==sStringToSelect) + aSelectionSet.insert(idx); + ++idx; + } - aSelectIndexes = findValue( getStringItemList(), sStringToSelect ); + aSelectIndexes = comphelper::containerToSequence<sal_Int16>( aSelectionSet ); } break; } @@ -1427,22 +1433,22 @@ namespace frm struct ExtractStringFromSequence_Safe : public ::std::unary_function< sal_Int16, OUString > { protected: - const Sequence< OUString >& m_rList; + const std::vector< OUString >& m_rList; public: - explicit ExtractStringFromSequence_Safe( const Sequence< OUString >& _rList ) : m_rList( _rList ) { } + explicit ExtractStringFromSequence_Safe( const std::vector< OUString >& _rList ) : m_rList( _rList ) { } OUString operator ()( sal_Int16 _nIndex ) { - OSL_ENSURE( _nIndex < m_rList.getLength(), "ExtractStringFromSequence_Safe: inconsistence!" ); - if ( _nIndex < m_rList.getLength() ) + OSL_ENSURE( _nIndex < (sal_Int32)m_rList.size(), "ExtractStringFromSequence_Safe: inconsistence!" ); + if ( _nIndex < (sal_Int32)m_rList.size() ) return m_rList[ _nIndex ]; return OUString(); } }; - Any lcl_getSingleSelectedEntry( const Sequence< sal_Int16 >& _rSelectSequence, const Sequence< OUString >& _rStringList ) + Any lcl_getSingleSelectedEntry( const Sequence< sal_Int16 >& _rSelectSequence, const std::vector< OUString >& _rStringList ) { Any aReturn; @@ -1462,7 +1468,7 @@ namespace frm } - Any lcl_getMultiSelectedEntries( const Sequence< sal_Int16 >& _rSelectSequence, const Sequence< OUString >& _rStringList ) + Any lcl_getMultiSelectedEntries( const Sequence< sal_Int16 >& _rSelectSequence, const std::vector< OUString >& _rStringList ) { Sequence< OUString > aSelectedEntriesTexts( _rSelectSequence.getLength() ); ::std::transform( @@ -1674,7 +1680,7 @@ namespace frm suspendValueListening(); try { - m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( getStringItemList() ) ); + m_xAggregateSet->setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( comphelper::containerToSequence(getStringItemList()) ) ); } catch( const Exception& ) { diff --git a/forms/source/component/entrylisthelper.cxx b/forms/source/component/entrylisthelper.cxx index b8acb0793ead..3d419b9ce5ab 100644 --- a/forms/source/component/entrylisthelper.cxx +++ b/forms/source/component/entrylisthelper.cxx @@ -81,13 +81,13 @@ namespace frm OSL_ENSURE( _rEvent.Source == m_xListSource, "OEntryListHelper::entryChanged: where did this come from?" ); - OSL_ENSURE( ( _rEvent.Position >= 0 ) && ( _rEvent.Position < m_aStringItems.getLength() ), + OSL_ENSURE( ( _rEvent.Position >= 0 ) && ( _rEvent.Position < (sal_Int32)m_aStringItems.size() ), "OEntryListHelper::entryChanged: invalid index!" ); OSL_ENSURE( _rEvent.Entries.getLength() == 1, "OEntryListHelper::entryChanged: invalid string list!" ); if ( ( _rEvent.Position >= 0 ) - && ( _rEvent.Position < m_aStringItems.getLength() ) + && ( _rEvent.Position < (sal_Int32)m_aStringItems.size() ) && ( _rEvent.Entries.getLength() > 0 ) ) { @@ -103,31 +103,15 @@ namespace frm OSL_ENSURE( _rEvent.Source == m_xListSource, "OEntryListHelper::entryRangeInserted: where did this come from?" ); - OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Position < m_aStringItems.getLength() ) && ( _rEvent.Entries.getLength() > 0 ), + OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Position < (sal_Int32)m_aStringItems.size() ) && ( _rEvent.Entries.getLength() > 0 ), "OEntryListHelper::entryRangeRemoved: invalid count and/or position!" ); if ( ( _rEvent.Position > 0 ) - && ( _rEvent.Position < m_aStringItems.getLength() ) + && ( _rEvent.Position < (sal_Int32)m_aStringItems.size() ) && ( _rEvent.Entries.getLength() > 0 ) ) { - // the entries *before* the insertion pos - Sequence< OUString > aKeepEntries( - m_aStringItems.getConstArray(), - _rEvent.Position - ); - // the entries *behind* the insertion pos - Sequence< OUString > aMovedEntries( - m_aStringItems.getConstArray() + _rEvent.Position, - m_aStringItems.getLength() - _rEvent.Position - ); - - // concat all three parts - m_aStringItems = ::comphelper::concatSequences( - aKeepEntries, - _rEvent.Entries, - aMovedEntries - ); + m_aStringItems.insert(m_aStringItems.begin() + _rEvent.Position, _rEvent.Entries.begin(), _rEvent.Entries.end()); stringItemListChanged( aLock ); } @@ -140,23 +124,16 @@ namespace frm OSL_ENSURE( _rEvent.Source == m_xListSource, "OEntryListHelper::entryRangeRemoved: where did this come from?" ); - OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Count > 0 ) && ( _rEvent.Position + _rEvent.Count <= m_aStringItems.getLength() ), + OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Count > 0 ) && ( _rEvent.Position + _rEvent.Count <= (sal_Int32)m_aStringItems.size() ), "OEntryListHelper::entryRangeRemoved: invalid count and/or position!" ); if ( ( _rEvent.Position > 0 ) && ( _rEvent.Count > 0 ) - && ( _rEvent.Position + _rEvent.Count <= m_aStringItems.getLength() ) + && ( _rEvent.Position + _rEvent.Count <= (sal_Int32)m_aStringItems.size() ) ) { - // copy all items after the removed ones - ::std::copy( - m_aStringItems.getConstArray() + _rEvent.Position + _rEvent.Count, - m_aStringItems.getConstArray() + m_aStringItems.getLength(), - m_aStringItems.getArray( ) + _rEvent.Position - ); - // shrink the array - m_aStringItems.realloc( m_aStringItems.getLength() - _rEvent.Count ); - + m_aStringItems.erase(m_aStringItems.begin() + _rEvent.Position, + m_aStringItems.begin() + _rEvent.Position + _rEvent.Count ); stringItemListChanged( aLock ); } } @@ -208,7 +185,7 @@ namespace frm { if ( hasExternalListSource() ) { - m_aStringItems = m_xListSource->getAllListEntries( ); + comphelper::sequenceToContainer(m_aStringItems, m_xListSource->getAllListEntries()); stringItemListChanged( _rInstanceLock ); } else @@ -274,7 +251,7 @@ namespace frm // be notified when the list changes ... m_xListSource->addListEntryListener( this ); - m_aStringItems = m_xListSource->getAllListEntries( ); + comphelper::sequenceToContainer( m_aStringItems, m_xListSource->getAllListEntries() ); stringItemListChanged( _rInstanceLock ); // let derivees react on the new list source @@ -290,14 +267,16 @@ namespace frm throw IllegalArgumentException( ); // TODO: error message - return ::comphelper::tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aStringItems ); + return ::comphelper::tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, comphelper::containerToSequence(m_aStringItems) ); } void OEntryListHelper::setNewStringItemList( const css::uno::Any& _rValue, ControlModelLock& _rInstanceLock ) { OSL_PRECOND( !hasExternalListSource(), "OEntryListHelper::setNewStringItemList: this should never have survived convertNewListSourceProperty!" ); - OSL_VERIFY( _rValue >>= m_aStringItems ); + css::uno::Sequence<OUString> aTmp; + OSL_VERIFY( _rValue >>= aTmp ); + comphelper::sequenceToContainer(m_aStringItems, aTmp); stringItemListChanged( _rInstanceLock ); } diff --git a/forms/source/component/entrylisthelper.hxx b/forms/source/component/entrylisthelper.hxx index c261e4e6cd0e..d2f205a88d00 100644 --- a/forms/source/component/entrylisthelper.hxx +++ b/forms/source/component/entrylisthelper.hxx @@ -51,7 +51,7 @@ namespace frm css::uno::Reference< css::form::binding::XListEntrySource > m_xListSource; /// our external list source - css::uno::Sequence< OUString > + std::vector< OUString > m_aStringItems; /// "overridden" StringItemList property value ::comphelper::OInterfaceContainerHelper2 m_aRefreshListeners; @@ -63,7 +63,7 @@ namespace frm virtual ~OEntryListHelper( ); /// returns the current string item list - inline const css::uno::Sequence< OUString >& + inline const std::vector< OUString >& getStringItemList() const { return m_aStringItems; } /// determines whether we actually have an external list source diff --git a/forms/source/inc/FormComponent.hxx b/forms/source/inc/FormComponent.hxx index eb5118e89f5f..201cf13f6b97 100644 --- a/forms/source/inc/FormComponent.hxx +++ b/forms/source/inc/FormComponent.hxx @@ -132,11 +132,11 @@ namespace frm void impl_notifyAll_nothrow(); private: - OControlModel& m_rModel; - bool m_bLocked; - css::uno::Sequence< sal_Int32 > m_aHandles; - css::uno::Sequence< css::uno::Any > m_aOldValues; - css::uno::Sequence< css::uno::Any > m_aNewValues; + OControlModel& m_rModel; + bool m_bLocked; + std::vector< sal_Int32 > m_aHandles; + std::vector< css::uno::Any > m_aOldValues; + std::vector< css::uno::Any > m_aNewValues; private: ControlModelLock( const ControlModelLock& ) = delete; @@ -496,6 +496,12 @@ public: oslInterlockedCount unlockInstance( LockAccess ); void firePropertyChanges( + const std::vector< sal_Int32 >& _rHandles, + const std::vector< css::uno::Any >& _rOldValues, + const std::vector< css::uno::Any >& _rNewValues, + LockAccess + ); + void firePropertyChanges( const css::uno::Sequence< sal_Int32 >& _rHandles, const css::uno::Sequence< css::uno::Any >& _rOldValues, const css::uno::Sequence< css::uno::Any >& _rNewValues, |