diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-09-03 20:24:49 +0300 |
---|---|---|
committer | Arkadiy Illarionov <qarkai@gmail.com> | 2019-09-05 14:53:10 +0200 |
commit | 396869e0e71bd33f5d962779abf72f35d01245e5 (patch) | |
tree | cc123c6864ff0db9875fe7e634de157eb34a9364 /accessibility | |
parent | tdf#127357 Make "Select Address List" dialog modal again (diff) | |
download | core-396869e0e71bd33f5d962779abf72f35d01245e5.tar.gz core-396869e0e71bd33f5d962779abf72f35d01245e5.zip |
Simplify Sequence iterations in accessibility
Use range-based loops, STL and comphelper functions.
Change-Id: I600f6eeffd606859c24cdce8faeaead29abfb843
Reviewed-on: https://gerrit.libreoffice.org/78573
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'accessibility')
11 files changed, 78 insertions, 140 deletions
diff --git a/accessibility/source/extended/AccessibleBrowseBoxHeaderBar.cxx b/accessibility/source/extended/AccessibleBrowseBoxHeaderBar.cxx index f22238fd1b17..5a88993125aa 100644 --- a/accessibility/source/extended/AccessibleBrowseBoxHeaderBar.cxx +++ b/accessibility/source/extended/AccessibleBrowseBoxHeaderBar.cxx @@ -343,7 +343,7 @@ sal_Int32 AccessibleBrowseBoxHeaderBar::implGetChildIndexFromSelectedIndex( if( (nSelectedChildIndex < 0) || (nSelectedChildIndex >= aSelSeq.getLength()) ) throw lang::IndexOutOfBoundsException(); - return aSelSeq[ nSelectedChildIndex ]; + return aSelSeq.getConstArray()[ nSelectedChildIndex ]; } void AccessibleBrowseBoxHeaderBar::ensureIsValidHeaderIndex( sal_Int32 nIndex ) diff --git a/accessibility/source/extended/AccessibleGridControlTable.cxx b/accessibility/source/extended/AccessibleGridControlTable.cxx index 587c8fb7b9dc..dabafb4b719e 100644 --- a/accessibility/source/extended/AccessibleGridControlTable.cxx +++ b/accessibility/source/extended/AccessibleGridControlTable.cxx @@ -165,17 +165,8 @@ sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 ensureIsAlive(); ensureIsValidRow( nRow ); - bool bSelected = false; Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows(); - for(int i=0; i<selectedRows.getLength(); i++) - { - if(nRow == selectedRows[i]) - { - bSelected = true; - break; - } - } - return bSelected; + return comphelper::findValue(selectedRows, nRow) != -1; } //columns aren't selectable diff --git a/accessibility/source/extended/textwindowaccessibility.cxx b/accessibility/source/extended/textwindowaccessibility.cxx index b1e8150d2163..d5cb9677cd5e 100644 --- a/accessibility/source/extended/textwindowaccessibility.cxx +++ b/accessibility/source/extended/textwindowaccessibility.cxx @@ -907,19 +907,6 @@ Document::retrieveCharacterBounds(Paragraph const * pParagraph, // XXX numeric overflow } -struct IndexCompare -{ - const css::beans::PropertyValue* pValues; - explicit IndexCompare(const css::beans::PropertyValue* pVals) - : pValues(pVals) - { - } - bool operator() ( sal_Int32 a, sal_Int32 b ) const - { - return pValues[a].Name < pValues[b].Name; - } -}; - css::uno::Sequence< css::beans::PropertyValue > Document::retrieveCharacterAttributes( Paragraph const * pParagraph, ::sal_Int32 nIndex, @@ -929,81 +916,65 @@ Document::retrieveCharacterAttributes( vcl::Font aFont = m_rEngine.GetFont(); const sal_Int32 AttributeCount = 9; - sal_Int32 i = 0; - css::uno::Sequence< css::beans::PropertyValue > aAttribs( AttributeCount ); + std::vector< css::beans::PropertyValue > aAttribs; + aAttribs.reserve(AttributeCount); + + css::beans::PropertyValue aAttrib; + aAttrib.Handle = -1; + aAttrib.State = css::beans::PropertyState_DIRECT_VALUE; //character background color - aAttribs[i].Name = "CharBackColor"; - aAttribs[i].Handle = -1; - aAttribs[i].Value = mapFontColor( aFont.GetFillColor() ); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharBackColor"; + aAttrib.Value = mapFontColor( aFont.GetFillColor() ); + aAttribs.push_back(aAttrib); //character color - aAttribs[i].Name = "CharColor"; - aAttribs[i].Handle = -1; - //aAttribs[i].Value = mapFontColor( aFont.GetColor() ); - aAttribs[i].Value = mapFontColor( m_rEngine.GetTextColor() ); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharColor"; + //aAttrib.Value = mapFontColor( aFont.GetColor() ); + aAttrib.Value = mapFontColor( m_rEngine.GetTextColor() ); + aAttribs.push_back(aAttrib); //character font name - aAttribs[i].Name = "CharFontName"; - aAttribs[i].Handle = -1; - aAttribs[i].Value <<= aFont.GetFamilyName(); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharFontName"; + aAttrib.Value <<= aFont.GetFamilyName(); + aAttribs.push_back(aAttrib); //character height - aAttribs[i].Name = "CharHeight"; - aAttribs[i].Handle = -1; - aAttribs[i].Value <<= static_cast<sal_Int16>(aFont.GetFontHeight()); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharHeight"; + aAttrib.Value <<= static_cast<sal_Int16>(aFont.GetFontHeight()); + aAttribs.push_back(aAttrib); //character posture - aAttribs[i].Name = "CharPosture"; - aAttribs[i].Handle = -1; - aAttribs[i].Value <<= static_cast<sal_Int16>(aFont.GetItalic()); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharPosture"; + aAttrib.Value <<= static_cast<sal_Int16>(aFont.GetItalic()); + aAttribs.push_back(aAttrib); //character relief /* - aAttribs[i].Name = "CharRelief"; - aAttribs[i].Handle = -1; - aAttribs[i].Value = css::uno::Any( (sal_Int16)aFont.GetRelief() ); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharRelief"; + aAttrib.Value = css::uno::Any( (sal_Int16)aFont.GetRelief() ); + aAttribs.push_back(aAttrib); */ //character strikeout - aAttribs[i].Name = "CharStrikeout"; - aAttribs[i].Handle = -1; - aAttribs[i].Value <<= static_cast<sal_Int16>(aFont.GetStrikeout()); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharStrikeout"; + aAttrib.Value <<= static_cast<sal_Int16>(aFont.GetStrikeout()); + aAttribs.push_back(aAttrib); //character underline - aAttribs[i].Name = "CharUnderline"; - aAttribs[i].Handle = -1; - aAttribs[i].Value <<= static_cast<sal_Int16>(aFont.GetUnderline()); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharUnderline"; + aAttrib.Value <<= static_cast<sal_Int16>(aFont.GetUnderline()); + aAttribs.push_back(aAttrib); //character weight - aAttribs[i].Name = "CharWeight"; - aAttribs[i].Handle = -1; - aAttribs[i].Value <<= static_cast<float>(aFont.GetWeight()); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "CharWeight"; + aAttrib.Value <<= static_cast<float>(aFont.GetWeight()); + aAttribs.push_back(aAttrib); //character alignment - aAttribs[i].Name = "ParaAdjust"; - aAttribs[i].Handle = -1; - aAttribs[i].Value <<= static_cast<sal_Int16>(m_rEngine.GetTextAlign()); - aAttribs[i].State = css::beans::PropertyState_DIRECT_VALUE; - i++; + aAttrib.Name = "ParaAdjust"; + aAttrib.Value <<= static_cast<sal_Int16>(m_rEngine.GetTextAlign()); + aAttribs.push_back(aAttrib); ::osl::MutexGuard aInternalGuard(GetMutex()); ::sal_uInt32 nNumber = static_cast< ::sal_uInt32 >(pParagraph->getNumber()); @@ -1020,30 +991,27 @@ Document::retrieveCharacterAttributes( tPropValMap aCharAttrSeq; retrieveRunAttributesImpl( pParagraph, nIndex, aRequestedAttributes, aCharAttrSeq ); - css::beans::PropertyValue* pValues = aAttribs.getArray(); - for (i = 0; i < AttributeCount; i++,pValues++) + for (const css::beans::PropertyValue& rAttrib : aAttribs) { - aCharAttrSeq[ pValues->Name ] = *pValues; + aCharAttrSeq[ rAttrib.Name ] = rAttrib; } - css::uno::Sequence< css::beans::PropertyValue > aRes = comphelper::mapValuesToSequence( aCharAttrSeq ); + const css::uno::Sequence< css::beans::PropertyValue > aRes = comphelper::mapValuesToSequence( aCharAttrSeq ); // sort the attributes - sal_Int32 nLength = aRes.getLength(); - const css::beans::PropertyValue* pPairs = aRes.getConstArray(); + auto nLength = static_cast<size_t>(aRes.getLength()); std::unique_ptr<sal_Int32[]> pIndices( new sal_Int32[nLength] ); - for( i = 0; i < nLength; i++ ) - pIndices[i] = i; - std::sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) ); + std::iota(&pIndices[0], &pIndices[nLength], 0); + std::sort(&pIndices[0], &pIndices[nLength], + [&aRes](sal_Int32 a, sal_Int32 b) { return aRes[a].Name < aRes[b].Name; }); + // create sorted sequences according to index array - css::uno::Sequence< css::beans::PropertyValue > aNewValues( nLength ); - css::beans::PropertyValue* pNewValues = aNewValues.getArray(); - for( i = 0; i < nLength; i++ ) - { - pNewValues[i] = pPairs[pIndices[i]]; - } + std::vector<css::beans::PropertyValue> aNewValues; + aNewValues.reserve(nLength); + std::transform(&pIndices[0], &pIndices[nLength], std::back_inserter(aNewValues), + [&aRes](const sal_Int32 nIdx) { return aRes[nIdx]; }); - return aNewValues; + return comphelper::containerToSequence(aNewValues); } void Document::retrieveRunAttributesImpl( @@ -1085,11 +1053,9 @@ void Document::retrieveRunAttributesImpl( } else { - const OUString* pReqAttrs = RequestedAttributes.getConstArray(); - const ::sal_Int32 nLength = RequestedAttributes.getLength(); - for ( ::sal_Int32 i = 0; i < nLength; ++i ) + for ( const OUString& rReqAttr : RequestedAttributes ) { - tPropValMap::iterator aIter = aRunAttrSeq.find( pReqAttrs[i] ); + tPropValMap::iterator aIter = aRunAttrSeq.find( rReqAttr ); if ( aIter != aRunAttrSeq.end() ) { rRunAttrSeq[ (*aIter).first ] = (*aIter).second; @@ -1194,15 +1160,15 @@ void Document::changeParagraphAttributes( // FIXME The new attributes are added to any attributes already set, // they do not replace the old attributes as required by // XAccessibleEditableText.setAttributes: - for (::sal_Int32 i = 0; i < rAttributeSet.getLength(); ++i) - if ( rAttributeSet[i].Name == "CharColor" ) + for (const auto& rAttr : rAttributeSet) + if ( rAttr.Name == "CharColor" ) m_rEngine.SetAttrib(::TextAttribFontColor( - mapFontColor(rAttributeSet[i].Value)), + mapFontColor(rAttr.Value)), nNumber, nBegin, nEnd); // XXX numeric overflow (2x) - else if ( rAttributeSet[i].Name == "CharWeight" ) + else if ( rAttr.Name == "CharWeight" ) m_rEngine.SetAttrib(::TextAttribFontWeight( - mapFontWeight(rAttributeSet[i].Value)), + mapFontWeight(rAttr.Value)), nNumber, nBegin, nEnd); // XXX numeric overflow (2x) } diff --git a/accessibility/source/standard/vclxaccessiblecombobox.cxx b/accessibility/source/standard/vclxaccessiblecombobox.cxx index 04f036f04fc1..fc749f8eb5ea 100644 --- a/accessibility/source/standard/vclxaccessiblecombobox.cxx +++ b/accessibility/source/standard/vclxaccessiblecombobox.cxx @@ -52,11 +52,8 @@ OUString VCLXAccessibleComboBox::getImplementationName() Sequence< OUString > VCLXAccessibleComboBox::getSupportedServiceNames() { - Sequence< OUString > aNames = VCLXAccessibleBox::getSupportedServiceNames(); - sal_Int32 nLength = aNames.getLength(); - aNames.realloc( nLength + 1 ); - aNames[nLength] = "com.sun.star.accessibility.AccessibleComboBox"; - return aNames; + return comphelper::concatSequences(VCLXAccessibleBox::getSupportedServiceNames(), + Sequence<OUString>{"com.sun.star.accessibility.AccessibleComboBox"}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/accessibility/source/standard/vclxaccessibledropdowncombobox.cxx b/accessibility/source/standard/vclxaccessibledropdowncombobox.cxx index 446165d6c413..295c34133f65 100644 --- a/accessibility/source/standard/vclxaccessibledropdowncombobox.cxx +++ b/accessibility/source/standard/vclxaccessibledropdowncombobox.cxx @@ -79,11 +79,8 @@ OUString VCLXAccessibleDropDownComboBox::getImplementationName() Sequence< OUString > VCLXAccessibleDropDownComboBox::getSupportedServiceNames() { - Sequence< OUString > aNames = VCLXAccessibleBox::getSupportedServiceNames(); - sal_Int32 nLength = aNames.getLength(); - aNames.realloc( nLength + 1 ); - aNames[nLength] = "com.sun.star.accessibility.AccessibleDropDownComboBox"; - return aNames; + return comphelper::concatSequences(VCLXAccessibleBox::getSupportedServiceNames(), + Sequence<OUString>{"com.sun.star.accessibility.AccessibleDropDownComboBox"}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/accessibility/source/standard/vclxaccessibledropdownlistbox.cxx b/accessibility/source/standard/vclxaccessibledropdownlistbox.cxx index 11da9de8c623..4422ed753417 100644 --- a/accessibility/source/standard/vclxaccessibledropdownlistbox.cxx +++ b/accessibility/source/standard/vclxaccessibledropdownlistbox.cxx @@ -63,11 +63,8 @@ OUString VCLXAccessibleDropDownListBox::getImplementationName() Sequence< OUString > VCLXAccessibleDropDownListBox::getSupportedServiceNames() { - Sequence< OUString > aNames = VCLXAccessibleBox::getSupportedServiceNames(); - sal_Int32 nLength = aNames.getLength(); - aNames.realloc( nLength + 1 ); - aNames[nLength] = "com.sun.star.accessibility.AccessibleDropDownListBox"; - return aNames; + return comphelper::concatSequences(VCLXAccessibleBox::getSupportedServiceNames(), + Sequence<OUString>{"com.sun.star.accessibility.AccessibleDropDownListBox"}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/accessibility/source/standard/vclxaccessiblelist.cxx b/accessibility/source/standard/vclxaccessiblelist.cxx index 313e4b416436..deb5ca1c723f 100644 --- a/accessibility/source/standard/vclxaccessiblelist.cxx +++ b/accessibility/source/standard/vclxaccessiblelist.cxx @@ -586,11 +586,8 @@ OUString VCLXAccessibleList::getImplementationName() Sequence< OUString > VCLXAccessibleList::getSupportedServiceNames() { - Sequence< OUString > aNames = VCLXAccessibleComponent::getSupportedServiceNames(); - sal_Int32 nLength = aNames.getLength(); - aNames.realloc( nLength + 1 ); - aNames[nLength] = "com.sun.star.accessibility.AccessibleList"; - return aNames; + return comphelper::concatSequences(VCLXAccessibleComponent::getSupportedServiceNames(), + Sequence<OUString>{"com.sun.star.accessibility.AccessibleList"}); } void VCLXAccessibleList::UpdateVisibleLineCount() diff --git a/accessibility/source/standard/vclxaccessiblelistbox.cxx b/accessibility/source/standard/vclxaccessiblelistbox.cxx index 7c3d7025518a..11d93207a584 100644 --- a/accessibility/source/standard/vclxaccessiblelistbox.cxx +++ b/accessibility/source/standard/vclxaccessiblelistbox.cxx @@ -62,11 +62,8 @@ OUString VCLXAccessibleListBox::getImplementationName() Sequence< OUString > VCLXAccessibleListBox::getSupportedServiceNames() { - Sequence< OUString > aNames = VCLXAccessibleBox::getSupportedServiceNames(); - sal_Int32 nLength = aNames.getLength(); - aNames.realloc( nLength + 1 ); - aNames[nLength] = "com.sun.star.accessibility.AccessibleListBox"; - return aNames; + return comphelper::concatSequences(VCLXAccessibleBox::getSupportedServiceNames(), + Sequence<OUString>{"com.sun.star.accessibility.AccessibleListBox"}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/accessibility/source/standard/vclxaccessibleradiobutton.cxx b/accessibility/source/standard/vclxaccessibleradiobutton.cxx index 7d4b7ec1d2fa..7a5d2effddca 100644 --- a/accessibility/source/standard/vclxaccessibleradiobutton.cxx +++ b/accessibility/source/standard/vclxaccessibleradiobutton.cxx @@ -81,10 +81,12 @@ void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelati std::vector< VclPtr<RadioButton> > aGroup(pRadioButton->GetRadioButtonGroup()); if (!aGroup.empty()) { - Sequence< Reference< XInterface > > aSequence( static_cast< sal_Int32 >( aGroup.size() ) ); - std::transform(aGroup.begin(), aGroup.end(), aSequence.getArray(), + std::vector< Reference< XInterface > > aVec; + aVec.reserve(aGroup.size()); + std::transform(aGroup.begin(), aGroup.end(), std::back_inserter(aVec), [](const VclPtr<RadioButton>& rxItem) { return rxItem->GetAccessible(); }); - rRelationSet.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, aSequence ) ); + rRelationSet.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, + comphelper::containerToSequence(aVec) ) ); } } } diff --git a/accessibility/source/standard/vclxaccessibletextfield.cxx b/accessibility/source/standard/vclxaccessibletextfield.cxx index 6837ee9eb7c3..65807da4408e 100644 --- a/accessibility/source/standard/vclxaccessibletextfield.cxx +++ b/accessibility/source/standard/vclxaccessibletextfield.cxx @@ -106,11 +106,8 @@ OUString VCLXAccessibleTextField::getImplementationName() Sequence< OUString > VCLXAccessibleTextField::getSupportedServiceNames() { - Sequence< OUString > aNames = VCLXAccessibleTextComponent::getSupportedServiceNames(); - sal_Int32 nLength = aNames.getLength(); - aNames.realloc( nLength + 1 ); - aNames[nLength] = "com.sun.star.accessibility.AccessibleTextField"; - return aNames; + return comphelper::concatSequences(VCLXAccessibleTextComponent::getSupportedServiceNames(), + Sequence<OUString>{"com.sun.star.accessibility.AccessibleTextField"}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/accessibility/source/standard/vclxaccessibletoolbox.cxx b/accessibility/source/standard/vclxaccessibletoolbox.cxx index 7d266d2b6de1..1508cf0b5184 100644 --- a/accessibility/source/standard/vclxaccessibletoolbox.cxx +++ b/accessibility/source/standard/vclxaccessibletoolbox.cxx @@ -662,11 +662,8 @@ OUString VCLXAccessibleToolBox::getImplementationName() Sequence< OUString > VCLXAccessibleToolBox::getSupportedServiceNames() { - Sequence< OUString > aNames = VCLXAccessibleComponent::getSupportedServiceNames(); - sal_Int32 nLength = aNames.getLength(); - aNames.realloc( nLength + 1 ); - aNames[nLength] = "com.sun.star.accessibility.AccessibleToolBox"; - return aNames; + return comphelper::concatSequences(VCLXAccessibleComponent::getSupportedServiceNames(), + Sequence<OUString>{"com.sun.star.accessibility.AccessibleToolBox"}); } // XAccessibleContext |