diff options
Diffstat (limited to 'accessibility/source/standard/vclxaccessibletoolbox.cxx')
-rw-r--r-- | accessibility/source/standard/vclxaccessibletoolbox.cxx | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/accessibility/source/standard/vclxaccessibletoolbox.cxx b/accessibility/source/standard/vclxaccessibletoolbox.cxx index a4f2f941492c..7f744038d505 100644 --- a/accessibility/source/standard/vclxaccessibletoolbox.cxx +++ b/accessibility/source/standard/vclxaccessibletoolbox.cxx @@ -694,7 +694,11 @@ Sequence< OUString > VCLXAccessibleToolBox::getSupportedServiceNames() sal_Int32 SAL_CALL VCLXAccessibleToolBox::getAccessibleChildCount( ) { comphelper::OExternalLockGuard aGuard( this ); + return implGetAccessibleChildCount(); +} + sal_Int32 VCLXAccessibleToolBox::implGetAccessibleChildCount( ) + { sal_Int32 nCount = 0; VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); if ( pToolBox ) @@ -706,49 +710,44 @@ sal_Int32 SAL_CALL VCLXAccessibleToolBox::getAccessibleChildCount( ) Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleChild( sal_Int32 i ) { - if ( i < 0 || i >= getAccessibleChildCount() ) - throw IndexOutOfBoundsException(); - comphelper::OExternalLockGuard aGuard( this ); VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); - if ( pToolBox ) + if ( (!pToolBox) || i < 0 || static_cast<size_t>(i) >= pToolBox->GetItemCount() ) + throw IndexOutOfBoundsException(); + + Reference< XAccessible > xChild; + // search for the child + ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find(i); + if ( m_aAccessibleChildren.end() == aIter ) { - Reference< XAccessible > xChild; - // search for the child - ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find(i); - if ( m_aAccessibleChildren.end() == aIter ) - { - sal_uInt16 nItemId = pToolBox->GetItemId( i ); - sal_uInt16 nHighlightItemId = pToolBox->GetHighlightItemId(); - vcl::Window* pItemWindow = pToolBox->GetItemWindow( nItemId ); - // not found -> create a new child - VCLXAccessibleToolBoxItem* pChild = new VCLXAccessibleToolBoxItem( pToolBox, i ); - Reference< XAccessible> xParent = pChild; - if ( pItemWindow ) - { - xChild = new OToolBoxWindowItem(0,::comphelper::getProcessComponentContext(),pItemWindow->GetAccessible(),xParent); - pItemWindow->SetAccessible(xChild); - pChild->SetChild( xChild ); - } - xChild = pChild; - if ( nHighlightItemId > 0 && nItemId == nHighlightItemId ) - pChild->SetFocus( true ); - if ( pToolBox->IsItemChecked( nItemId ) ) - pChild->SetChecked( true ); - if ( pToolBox->GetItemState( nItemId ) == TRISTATE_INDET ) - pChild->SetIndeterminate( true ); - m_aAccessibleChildren.emplace( i, xChild ); - } - else + sal_uInt16 nItemId = pToolBox->GetItemId( i ); + sal_uInt16 nHighlightItemId = pToolBox->GetHighlightItemId(); + vcl::Window* pItemWindow = pToolBox->GetItemWindow( nItemId ); + // not found -> create a new child + VCLXAccessibleToolBoxItem* pChild = new VCLXAccessibleToolBoxItem( pToolBox, i ); + Reference< XAccessible> xParent = pChild; + if ( pItemWindow ) { - // found it - xChild = aIter->second; + xChild = new OToolBoxWindowItem(0,::comphelper::getProcessComponentContext(),pItemWindow->GetAccessible(),xParent); + pItemWindow->SetAccessible(xChild); + pChild->SetChild( xChild ); } - return xChild; + xChild = pChild; + if ( nHighlightItemId > 0 && nItemId == nHighlightItemId ) + pChild->SetFocus( true ); + if ( pToolBox->IsItemChecked( nItemId ) ) + pChild->SetChecked( true ); + if ( pToolBox->GetItemState( nItemId ) == TRISTATE_INDET ) + pChild->SetIndeterminate( true ); + m_aAccessibleChildren.emplace( i, xChild ); } - - return nullptr; + else + { + // found it + xChild = aIter->second; + } + return xChild; } Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleAtPoint( const awt::Point& _rPoint ) @@ -801,19 +800,22 @@ Reference< XAccessible > VCLXAccessibleToolBox::GetChildAccessible( const VclWin void VCLXAccessibleToolBox::selectAccessibleChild( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) - throw IndexOutOfBoundsException(); + VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); + if ( (!pToolBox) || nChildIndex < 0 || static_cast<size_t> (nChildIndex) >= pToolBox->GetItemCount() ) + throw IndexOutOfBoundsException(); + pToolBox->ChangeHighlight( nChildIndex ); } sal_Bool VCLXAccessibleToolBox::isAccessibleChildSelected( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) - throw IndexOutOfBoundsException(); VclPtr< ToolBox > pToolBox = GetAs< ToolBox >(); - if ( pToolBox && pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nChildIndex ) ) + if ( (!pToolBox) || nChildIndex < 0 || static_cast<size_t>(nChildIndex) >= pToolBox->GetItemCount() ) + throw IndexOutOfBoundsException(); + + if ( pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nChildIndex ) ) return true; else return false; @@ -835,8 +837,9 @@ void VCLXAccessibleToolBox::selectAllAccessibleChildren( ) sal_Int32 VCLXAccessibleToolBox::getSelectedAccessibleChildCount( ) { OExternalLockGuard aGuard( this ); + sal_Int32 nRet = 0; - for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; i++ ) + for ( sal_Int32 i = 0, nCount = implGetAccessibleChildCount(); i < nCount; i++ ) { if ( isAccessibleChildSelected( i ) ) { @@ -850,24 +853,28 @@ sal_Int32 VCLXAccessibleToolBox::getSelectedAccessibleChildCount( ) Reference< XAccessible > VCLXAccessibleToolBox::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) + if ( nSelectedChildIndex != 0 ) throw IndexOutOfBoundsException(); + Reference< XAccessible > xChild; - for ( sal_Int32 i = 0, j = 0, nCount = getAccessibleChildCount(); i < nCount; i++ ) + for ( sal_Int32 i = 0, nCount = implGetAccessibleChildCount(); i < nCount; i++ ) { - if ( isAccessibleChildSelected( i ) && ( j++ == nSelectedChildIndex ) ) + if ( isAccessibleChildSelected( i ) ) { xChild = getAccessibleChild( i ); break; } } + if (!xChild) + throw IndexOutOfBoundsException(); + return xChild; } void VCLXAccessibleToolBox::deselectAccessibleChild( sal_Int32 nChildIndex ) { OExternalLockGuard aGuard( this ); - if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() ) + if ( nChildIndex < 0 || nChildIndex >= implGetAccessibleChildCount() ) throw IndexOutOfBoundsException(); clearAccessibleSelection(); // a toolbox can only have (n)one selected child } |