diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-06 11:29:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-06 12:47:53 +0200 |
commit | a814825461b1fc26288655535b64fc38b18ecf15 (patch) | |
tree | 47f3bad69292d3587bca73f6cdcd838b182d82cb /svx/source | |
parent | 1de2b0d3234462b488db54d36ebc17e2b579b0f0 (diff) |
loplugin:flatten in svx/accessibility
Change-Id: Id2c82625fc5cf0d139ea77489578bfce7abc3fa2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100206
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/accessibility/AccessibleControlShape.cxx | 54 | ||||
-rw-r--r-- | svx/source/accessibility/AccessibleShape.cxx | 86 | ||||
-rw-r--r-- | svx/source/accessibility/AccessibleTextHelper.cxx | 159 | ||||
-rw-r--r-- | svx/source/accessibility/ChildrenManagerImpl.cxx | 268 | ||||
-rw-r--r-- | svx/source/accessibility/DescriptionGenerator.cxx | 104 | ||||
-rw-r--r-- | svx/source/accessibility/GraphCtlAccessibleContext.cxx | 58 | ||||
-rw-r--r-- | svx/source/accessibility/lookupcolorname.cxx | 32 | ||||
-rw-r--r-- | svx/source/accessibility/svxrectctaccessiblecontext.cxx | 70 |
8 files changed, 418 insertions, 413 deletions
diff --git a/svx/source/accessibility/AccessibleControlShape.cxx b/svx/source/accessibility/AccessibleControlShape.cxx index 2eaf8448f9c5..74b8021ea38f 100644 --- a/svx/source/accessibility/AccessibleControlShape.cxx +++ b/svx/source/accessibility/AccessibleControlShape.cxx @@ -794,22 +794,22 @@ void AccessibleControlShape::initializeComposedState() // get my inner context Reference< XAccessibleContext > xInnerContext( m_aControlContext ); OSL_PRECOND( xInnerContext.is(), "AccessibleControlShape::initializeComposedState: no inner context!" ); - if ( xInnerContext.is() ) - { - // get all states of the inner context - Reference< XAccessibleStateSet > xInnerStates( xInnerContext->getAccessibleStateSet() ); - OSL_ENSURE( xInnerStates.is(), "AccessibleControlShape::initializeComposedState: no inner states!" ); - Sequence< sal_Int16 > aInnerStates; - if ( xInnerStates.is() ) - aInnerStates = xInnerStates->getStates(); + if ( !xInnerContext.is() ) + return; - // look which one are to be propagated to the composed context - for ( const sal_Int16 nState : aInnerStates ) + // get all states of the inner context + Reference< XAccessibleStateSet > xInnerStates( xInnerContext->getAccessibleStateSet() ); + OSL_ENSURE( xInnerStates.is(), "AccessibleControlShape::initializeComposedState: no inner states!" ); + Sequence< sal_Int16 > aInnerStates; + if ( xInnerStates.is() ) + aInnerStates = xInnerStates->getStates(); + + // look which one are to be propagated to the composed context + for ( const sal_Int16 nState : aInnerStates ) + { + if ( isComposedState( nState ) && !pComposedStates->contains( nState ) ) { - if ( isComposedState( nState ) && !pComposedStates->contains( nState ) ) - { - pComposedStates->AddState( nState ); - } + pComposedStates->AddState( nState ); } } } @@ -829,22 +829,22 @@ void SAL_CALL AccessibleControlShape::elementInserted( const css::container::Con Reference< XInterface > xNewNormalized( xControl->getModel(), UNO_QUERY ); Reference< XInterface > xMyModelNormalized( m_xControlModel, UNO_QUERY ); - if ( xNewNormalized && xMyModelNormalized ) - { - // now finally the control for the model we're responsible for has been inserted into the container - Reference< XInterface > xKeepAlive( *this ); + if ( !(xNewNormalized && xMyModelNormalized) ) + return; - // first, we're not interested in any more container events - if ( xContainer.is() ) - { - xContainer->removeContainerListener( this ); - m_bWaitingForControl = false; - } + // now finally the control for the model we're responsible for has been inserted into the container + Reference< XInterface > xKeepAlive( *this ); - // second, we need to replace ourself with a new version, which now can be based on the - // control - OSL_VERIFY( mpParent->ReplaceChild ( this, mxShape, 0, maShapeTreeInfo ) ); + // first, we're not interested in any more container events + if ( xContainer.is() ) + { + xContainer->removeContainerListener( this ); + m_bWaitingForControl = false; } + + // second, we need to replace ourself with a new version, which now can be based on the + // control + OSL_VERIFY( mpParent->ReplaceChild ( this, mxShape, 0, maShapeTreeInfo ) ); } void SAL_CALL AccessibleControlShape::elementRemoved( const css::container::ContainerEvent& ) diff --git a/svx/source/accessibility/AccessibleShape.cxx b/svx/source/accessibility/AccessibleShape.cxx index 3285f1ceb037..6e4891d4f011 100644 --- a/svx/source/accessibility/AccessibleShape.cxx +++ b/svx/source/accessibility/AccessibleShape.cxx @@ -139,37 +139,37 @@ void AccessibleShape::Init() // depths of the core. Necessary for making the edit engine // accessible. Reference<text::XText> xText (mxShape, uno::UNO_QUERY); - if (xText.is()) - { - SdrView* pView = maShapeTreeInfo.GetSdrView (); - const vcl::Window* pWindow = maShapeTreeInfo.GetWindow (); - if (pView != nullptr && pWindow != nullptr && mxShape.is()) - { - // #107948# Determine whether shape text is empty - SdrObject* pSdrObject = GetSdrObjectFromXShape(mxShape); - if( pSdrObject ) - { - SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>( pSdrObject ); - const bool hasOutlinerParaObject = (pTextObj && pTextObj->CanCreateEditOutlinerParaObject()) || (pSdrObject->GetOutlinerParaObject() != nullptr); + if (!xText.is()) + return; - // create AccessibleTextHelper to handle this shape's text - if( !hasOutlinerParaObject ) - { - // empty text -> use proxy edit source to delay creation of EditEngine - mpText.reset( new AccessibleTextHelper( std::make_unique<AccessibleEmptyEditSource >(*pSdrObject, *pView, *pWindow) ) ); - } - else - { - // non-empty text -> use full-fledged edit source right away - mpText.reset( new AccessibleTextHelper( std::make_unique<SvxTextEditSource >(*pSdrObject, nullptr, *pView, *pWindow) ) ); - } - if( pWindow->HasFocus() ) - mpText->SetFocus(); + SdrView* pView = maShapeTreeInfo.GetSdrView (); + const vcl::Window* pWindow = maShapeTreeInfo.GetWindow (); + if (!(pView != nullptr && pWindow != nullptr && mxShape.is())) + return; - mpText->SetEventSource(this); - } - } + // #107948# Determine whether shape text is empty + SdrObject* pSdrObject = GetSdrObjectFromXShape(mxShape); + if( !pSdrObject ) + return; + + SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>( pSdrObject ); + const bool hasOutlinerParaObject = (pTextObj && pTextObj->CanCreateEditOutlinerParaObject()) || (pSdrObject->GetOutlinerParaObject() != nullptr); + + // create AccessibleTextHelper to handle this shape's text + if( !hasOutlinerParaObject ) + { + // empty text -> use proxy edit source to delay creation of EditEngine + mpText.reset( new AccessibleTextHelper( std::make_unique<AccessibleEmptyEditSource >(*pSdrObject, *pView, *pWindow) ) ); + } + else + { + // non-empty text -> use full-fledged edit source right away + mpText.reset( new AccessibleTextHelper( std::make_unique<SvxTextEditSource >(*pSdrObject, nullptr, *pView, *pWindow) ) ); } + if( pWindow->HasFocus() ) + mpText->SetFocus(); + + mpText->SetEventSource(this); } @@ -917,24 +917,24 @@ void AccessibleShape::disposing (const lang::EventObject& aEvent) void SAL_CALL AccessibleShape::notifyShapeEvent (const document::EventObject& rEventObject) { - if (rEventObject.EventName == "ShapeModified") - { - //Need to update text children when receiving ShapeModified hint when exiting edit mode for text box - if (mpText) - mpText->UpdateChildren(); + if (rEventObject.EventName != "ShapeModified") + return; + //Need to update text children when receiving ShapeModified hint when exiting edit mode for text box + if (mpText) + mpText->UpdateChildren(); - // Some property of a shape has been modified. Send an event - // that indicates a change of the visible data to all listeners. - CommitChange ( - AccessibleEventId::VISIBLE_DATA_CHANGED, - uno::Any(), - uno::Any()); - // Name and Description may have changed. Update the local - // values accordingly. - UpdateNameAndDescription(); - } + // Some property of a shape has been modified. Send an event + // that indicates a change of the visible data to all listeners. + CommitChange ( + AccessibleEventId::VISIBLE_DATA_CHANGED, + uno::Any(), + uno::Any()); + + // Name and Description may have changed. Update the local + // values accordingly. + UpdateNameAndDescription(); } // lang::XUnoTunnel diff --git a/svx/source/accessibility/AccessibleTextHelper.cxx b/svx/source/accessibility/AccessibleTextHelper.cxx index 9a61a38638f4..625a9034831b 100644 --- a/svx/source/accessibility/AccessibleTextHelper.cxx +++ b/svx/source/accessibility/AccessibleTextHelper.cxx @@ -398,42 +398,42 @@ namespace accessibility mbThisHasFocus = bHaveFocus; - if( bOldFocus != bHaveFocus ) + if( bOldFocus == bHaveFocus ) + return; + + if( bHaveFocus ) { - if( bHaveFocus ) + if( mxFrontEnd.is() ) { - if( mxFrontEnd.is() ) + AccessibleCell* pAccessibleCell = dynamic_cast< AccessibleCell* > ( mxFrontEnd.get() ); + if ( !pAccessibleCell ) + GotPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED ); + else // the focus event on cell should be fired on table directly { - AccessibleCell* pAccessibleCell = dynamic_cast< AccessibleCell* > ( mxFrontEnd.get() ); - if ( !pAccessibleCell ) - GotPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED ); - else // the focus event on cell should be fired on table directly - { - AccessibleTableShape* pAccTable = pAccessibleCell->GetParentTable(); - if (pAccTable) - pAccTable->SetStateDirectly(AccessibleStateType::FOCUSED); - } + AccessibleTableShape* pAccTable = pAccessibleCell->GetParentTable(); + if (pAccTable) + pAccTable->SetStateDirectly(AccessibleStateType::FOCUSED); } - SAL_INFO("svx", "Parent object received focus" ); } - else + SAL_INFO("svx", "Parent object received focus" ); + } + else + { + // The focus state should be reset directly on table. + //LostPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED ); + if( mxFrontEnd.is() ) { - // The focus state should be reset directly on table. - //LostPropertyEvent( uno::makeAny(AccessibleStateType::FOCUSED), AccessibleEventId::STATE_CHANGED ); - if( mxFrontEnd.is() ) + AccessibleCell* pAccessibleCell = dynamic_cast< AccessibleCell* > ( mxFrontEnd.get() ); + if ( !pAccessibleCell ) + FireEvent( AccessibleEventId::STATE_CHANGED, uno::Any(), uno::makeAny(AccessibleStateType::FOCUSED) ); + else { - AccessibleCell* pAccessibleCell = dynamic_cast< AccessibleCell* > ( mxFrontEnd.get() ); - if ( !pAccessibleCell ) - FireEvent( AccessibleEventId::STATE_CHANGED, uno::Any(), uno::makeAny(AccessibleStateType::FOCUSED) ); - else - { - AccessibleTableShape* pAccTable = pAccessibleCell->GetParentTable(); - if (pAccTable) - pAccTable->ResetStateDirectly(AccessibleStateType::FOCUSED); - } + AccessibleTableShape* pAccTable = pAccessibleCell->GetParentTable(); + if (pAccTable) + pAccTable->ResetStateDirectly(AccessibleStateType::FOCUSED); } - SAL_INFO("svx", "Parent object lost focus" ); } + SAL_INFO("svx", "Parent object lost focus" ); } } @@ -914,32 +914,32 @@ namespace accessibility nLast = nLast + nMiddle - nFirst; } - if( nFirst < nParas && nMiddle < nParas && nLast < nParas ) - { - // since we have no "paragraph index - // changed" event on UAA, remove - // [first,last] and insert again later (in - // UpdateVisibleChildren) + if( !(nFirst < nParas && nMiddle < nParas && nLast < nParas) ) + return; - // maParaManager.Rotate( nFirst, nMiddle, nLast ); + // since we have no "paragraph index + // changed" event on UAA, remove + // [first,last] and insert again later (in + // UpdateVisibleChildren) - // send CHILD_EVENT to affected children - ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator begin = maParaManager.begin(); - ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator end = begin; + // maParaManager.Rotate( nFirst, nMiddle, nLast ); - ::std::advance( begin, nFirst ); - ::std::advance( end, nLast+1 ); + // send CHILD_EVENT to affected children + ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator begin = maParaManager.begin(); + ::accessibility::AccessibleParaManager::VectorOfChildren::const_iterator end = begin; - // TODO: maybe optimize here in the following way. If the - // number of removed children exceeds a certain threshold, - // use InvalidateFlags::Children - AccessibleTextHelper_LostChildEvent aFunctor( *this ); + ::std::advance( begin, nFirst ); + ::std::advance( end, nLast+1 ); - ::std::for_each( begin, end, aFunctor ); + // TODO: maybe optimize here in the following way. If the + // number of removed children exceeds a certain threshold, + // use InvalidateFlags::Children + AccessibleTextHelper_LostChildEvent aFunctor( *this ); - maParaManager.Release(nFirst, nLast+1); - // should be no need for UpdateBoundRect, since all affected children are cleared. - } + ::std::for_each( begin, end, aFunctor ); + + maParaManager.Release(nFirst, nLast+1); + // should be no need for UpdateBoundRect, since all affected children are cleared. } namespace { @@ -969,28 +969,27 @@ namespace accessibility {} void operator()( const SfxHint* pEvent ) { - if( pEvent && - mnParasChanged != -1 ) - { - // determine hint type - const TextHint* pTextHint = dynamic_cast<const TextHint*>( pEvent ); - const SvxEditSourceHint* pEditSourceHint = dynamic_cast<const SvxEditSourceHint*>( pEvent ); + if( !pEvent || mnParasChanged == -1 ) + return; - if( !pEditSourceHint && pTextHint && - (pTextHint->GetId() == SfxHintId::TextParaInserted || - pTextHint->GetId() == SfxHintId::TextParaRemoved ) ) - { - if( pTextHint->GetValue() == EE_PARA_ALL ) - { - mnParasChanged = -1; - } - else - { - mnHintId = pTextHint->GetId(); - mnParaIndex = pTextHint->GetValue(); - ++mnParasChanged; - } - } + // determine hint type + const TextHint* pTextHint = dynamic_cast<const TextHint*>( pEvent ); + const SvxEditSourceHint* pEditSourceHint = dynamic_cast<const SvxEditSourceHint*>( pEvent ); + + if( !(!pEditSourceHint && pTextHint && + (pTextHint->GetId() == SfxHintId::TextParaInserted || + pTextHint->GetId() == SfxHintId::TextParaRemoved )) ) + return; + + if( pTextHint->GetValue() == EE_PARA_ALL ) + { + mnParasChanged = -1; + } + else + { + mnHintId = pTextHint->GetId(); + mnParaIndex = pTextHint->GetValue(); + ++mnParasChanged; } } @@ -1466,19 +1465,19 @@ namespace accessibility void AccessibleTextHelper_Impl::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) { - if( getNotifierClientId() != -1 ) + if( getNotifierClientId() == -1 ) + return; + + const sal_Int32 nListenerCount = ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener ); + if ( !nListenerCount ) { - const sal_Int32 nListenerCount = ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener ); - if ( !nListenerCount ) - { - // no listeners anymore - // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client), - // and at least to us not firing any events anymore, in case somebody calls - // NotifyAccessibleEvent, again - ::comphelper::AccessibleEventNotifier::TClientId nId( getNotifierClientId() ); - mnNotifierClientId = -1; - ::comphelper::AccessibleEventNotifier::revokeClient( nId ); - } + // no listeners anymore + // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client), + // and at least to us not firing any events anymore, in case somebody calls + // NotifyAccessibleEvent, again + ::comphelper::AccessibleEventNotifier::TClientId nId( getNotifierClientId() ); + mnNotifierClientId = -1; + ::comphelper::AccessibleEventNotifier::revokeClient( nId ); } } diff --git a/svx/source/accessibility/ChildrenManagerImpl.cxx b/svx/source/accessibility/ChildrenManagerImpl.cxx index b24f70688b6f..c5214d406bbb 100644 --- a/svx/source/accessibility/ChildrenManagerImpl.cxx +++ b/svx/source/accessibility/ChildrenManagerImpl.cxx @@ -248,21 +248,21 @@ void ChildrenManagerImpl::Update (bool bCreateNewObjectsOnDemand) // 6. If children have to be created immediately and not on demand then // create the missing accessible objects now. - if (!bCreateNewObjectsOnDemand) - { - //operate on a copy of the list and restore it afterwards to guard - //against the pathological case where maVisibleChildren gets modified - //by other calls to this object while CreateAccessibilityObjects - //executes which can happen when java is disabled and the "enable-java" - //dialog appears during the instantiation of the linguistic components - //triggered by the creation of shapes belonging to the a11y objects - // - //i.e. launch start-center, launch impress with java disabled and - //a java-using linguistic component installed - maVisibleChildren.swap(aChildList); - CreateAccessibilityObjects(aChildList); - maVisibleChildren.swap(aChildList); - } + if (bCreateNewObjectsOnDemand) + return; + + //operate on a copy of the list and restore it afterwards to guard + //against the pathological case where maVisibleChildren gets modified + //by other calls to this object while CreateAccessibilityObjects + //executes which can happen when java is disabled and the "enable-java" + //dialog appears during the instantiation of the linguistic components + //triggered by the creation of shapes belonging to the a11y objects + // + //i.e. launch start-center, launch impress with java disabled and + //a java-using linguistic component installed + maVisibleChildren.swap(aChildList); + CreateAccessibilityObjects(aChildList); + maVisibleChildren.swap(aChildList); } void ChildrenManagerImpl::CreateListOfVisibleShapes ( @@ -294,30 +294,30 @@ void ChildrenManagerImpl::CreateListOfVisibleShapes ( } // Add the visible shapes for which only the XShapes exist. - if (mxShapeList.is()) + if (!mxShapeList.is()) + return; + + sal_Int32 nShapeCount = mxShapeList->getCount(); + raDescriptorList.reserve( nShapeCount ); + awt::Point aPos; + awt::Size aSize; + tools::Rectangle aBoundingBox; + uno::Reference<drawing::XShape> xShape; + for (sal_Int32 i=0; i<nShapeCount; ++i) { - sal_Int32 nShapeCount = mxShapeList->getCount(); - raDescriptorList.reserve( nShapeCount ); - awt::Point aPos; - awt::Size aSize; - tools::Rectangle aBoundingBox; - uno::Reference<drawing::XShape> xShape; - for (sal_Int32 i=0; i<nShapeCount; ++i) - { - mxShapeList->getByIndex(i) >>= xShape; - aPos = xShape->getPosition(); - aSize = xShape->getSize(); - - aBoundingBox.SetLeft( aPos.X ); - aBoundingBox.SetTop( aPos.Y ); - aBoundingBox.SetRight( aPos.X + aSize.Width ); - aBoundingBox.SetBottom( aPos.Y + aSize.Height ); - - // Insert shape if it is visible, i.e. its bounding box overlaps - // the visible area. - if ( aBoundingBox.IsOver (aVisibleArea) ) - raDescriptorList.emplace_back(xShape); - } + mxShapeList->getByIndex(i) >>= xShape; + aPos = xShape->getPosition(); + aSize = xShape->getSize(); + + aBoundingBox.SetLeft( aPos.X ); + aBoundingBox.SetTop( aPos.Y ); + aBoundingBox.SetRight( aPos.X + aSize.Width ); + aBoundingBox.SetBottom( aPos.Y + aSize.Height ); + + // Insert shape if it is visible, i.e. its bounding box overlaps + // the visible area. + if ( aBoundingBox.IsOver (aVisibleArea) ) + raDescriptorList.emplace_back(xShape); } } @@ -415,78 +415,80 @@ void ChildrenManagerImpl::CreateAccessibilityObjects ( void ChildrenManagerImpl::AddShape (const Reference<drawing::XShape>& rxShape) { - if (rxShape.is()) - { - SolarMutexClearableGuard aGuard; - - // Test visibility of the shape. - tools::Rectangle aVisibleArea = maShapeTreeInfo.GetViewForwarder()->GetVisibleArea(); - awt::Point aPos = rxShape->getPosition(); - awt::Size aSize = rxShape->getSize(); - - tools::Rectangle aBoundingBox ( - aPos.X, - aPos.Y, - aPos.X + aSize.Width, - aPos.Y + aSize.Height); - - // Add the shape only when it belongs to the list of shapes stored - // in mxShapeList (which is either a page or a group shape). - Reference<container::XChild> xChild (rxShape, uno::UNO_QUERY); - if (xChild.is()) - { - Reference<drawing::XShapes> xParent (xChild->getParent(), uno::UNO_QUERY); - if (xParent == mxShapeList) - if (aBoundingBox.IsOver (aVisibleArea)) - { - // Add shape to list of visible shapes. - maVisibleChildren.emplace_back(rxShape); - - // Create accessibility object. - ChildDescriptor& rDescriptor = maVisibleChildren.back(); - GetChild (rDescriptor, maVisibleChildren.size()-1); - - // Inform listeners about new child. - uno::Any aNewShape; - aNewShape <<= rDescriptor.mxAccessibleShape; - aGuard.clear(); - mrContext.CommitChange ( - AccessibleEventId::CHILD, - aNewShape, - uno::Any()); - RegisterAsDisposeListener(rxShape); - } - } - } + if (!rxShape.is()) + return; + + SolarMutexClearableGuard aGuard; + + // Test visibility of the shape. + tools::Rectangle aVisibleArea = maShapeTreeInfo.GetViewForwarder()->GetVisibleArea(); + awt::Point aPos = rxShape->getPosition(); + awt::Size aSize = rxShape->getSize(); + + tools::Rectangle aBoundingBox ( + aPos.X, + aPos.Y, + aPos.X + aSize.Width, + aPos.Y + aSize.Height); + + // Add the shape only when it belongs to the list of shapes stored + // in mxShapeList (which is either a page or a group shape). + Reference<container::XChild> xChild (rxShape, uno::UNO_QUERY); + if (!xChild.is()) + return; + + Reference<drawing::XShapes> xParent (xChild->getParent(), uno::UNO_QUERY); + if (xParent != mxShapeList) + return; + + if (!aBoundingBox.IsOver (aVisibleArea)) + return; + + // Add shape to list of visible shapes. + maVisibleChildren.emplace_back(rxShape); + + // Create accessibility object. + ChildDescriptor& rDescriptor = maVisibleChildren.back(); + GetChild (rDescriptor, maVisibleChildren.size()-1); + + // Inform listeners about new child. + uno::Any aNewShape; + aNewShape <<= rDescriptor.mxAccessibleShape; + aGuard.clear(); + mrContext.CommitChange ( + AccessibleEventId::CHILD, + aNewShape, + uno::Any()); + RegisterAsDisposeListener(rxShape); } void ChildrenManagerImpl::RemoveShape (const Reference<drawing::XShape>& rxShape) { - if (rxShape.is()) - { - SolarMutexGuard g; + if (!rxShape.is()) + return; - // Search shape in list of visible children. - ChildDescriptorListType::iterator I ( - ::std::find (maVisibleChildren.begin(), maVisibleChildren.end(), - ChildDescriptor (rxShape))); - if (I != maVisibleChildren.end()) - { - // Remove descriptor from that list. - Reference<XAccessible> xHoldAlive(I->mxAccessibleShape); + SolarMutexGuard g; - UnregisterAsDisposeListener (I->mxShape); - // Dispose the accessible object. - I->disposeAccessibleObject (mrContext); + // Search shape in list of visible children. + ChildDescriptorListType::iterator I ( + ::std::find (maVisibleChildren.begin(), maVisibleChildren.end(), + ChildDescriptor (rxShape))); + if (I == maVisibleChildren.end()) + return; - // Now we can safely remove the child descriptor and thus - // invalidate the iterator. - maVisibleChildren.erase (I); + // Remove descriptor from that list. + Reference<XAccessible> xHoldAlive(I->mxAccessibleShape); - adjustIndexInParentOfShapes(maVisibleChildren); - } - } + UnregisterAsDisposeListener (I->mxShape); + // Dispose the accessible object. + I->disposeAccessibleObject (mrContext); + + // Now we can safely remove the child descriptor and thus + // invalidate the iterator. + maVisibleChildren.erase (I); + + adjustIndexInParentOfShapes(maVisibleChildren); } @@ -576,27 +578,27 @@ void ChildrenManagerImpl::SetInfo (const AccessibleShapeTreeInfo& rShapeTreeInfo Reference<frame::XController> xNewController(maShapeTreeInfo.GetController()); Reference<view::XSelectionSupplier> xNewSelectionSupplier ( xNewController, uno::UNO_QUERY); - if (xNewSelectionSupplier != xCurrentSelectionSupplier) + if (xNewSelectionSupplier == xCurrentSelectionSupplier) + return; + + // Register at new broadcaster. + if (xNewSelectionSupplier.is()) { - // Register at new broadcaster. - if (xNewSelectionSupplier.is()) - { - xNewController->addEventListener( - static_cast<document::XEventListener*>(this)); + xNewController->addEventListener( + static_cast<document::XEventListener*>(this)); - xNewSelectionSupplier->addSelectionChangeListener ( - static_cast<view::XSelectionChangeListener*>(this)); - } + xNewSelectionSupplier->addSelectionChangeListener ( + static_cast<view::XSelectionChangeListener*>(this)); + } - // Unregister at old broadcaster. - if (xCurrentSelectionSupplier.is()) - { - xCurrentSelectionSupplier->removeSelectionChangeListener ( - static_cast<view::XSelectionChangeListener*>(this)); + // Unregister at old broadcaster. + if (xCurrentSelectionSupplier.is()) + { + xCurrentSelectionSupplier->removeSelectionChangeListener ( + static_cast<view::XSelectionChangeListener*>(this)); - xCurrentController->removeEventListener( - static_cast<document::XEventListener*>(this)); - } + xCurrentController->removeEventListener( + static_cast<document::XEventListener*>(this)); } } @@ -1016,23 +1018,23 @@ void ChildDescriptor::setIndexAtAccessibleShape(sal_Int32 _nIndex) void ChildDescriptor::disposeAccessibleObject (AccessibleContextBase& rParent) { - if (mxAccessibleShape.is()) - { - // Send event that the shape has been removed. - uno::Any aOldValue; - aOldValue <<= mxAccessibleShape; - rParent.CommitChange ( - AccessibleEventId::CHILD, - uno::Any(), - aOldValue); + if (!mxAccessibleShape.is()) + return; - // Dispose and remove the object. - Reference<lang::XComponent> xComponent (mxAccessibleShape, uno::UNO_QUERY); - if (xComponent.is()) - xComponent->dispose (); + // Send event that the shape has been removed. + uno::Any aOldValue; + aOldValue <<= mxAccessibleShape; + rParent.CommitChange ( + AccessibleEventId::CHILD, + uno::Any(), + aOldValue); - mxAccessibleShape = nullptr; - } + // Dispose and remove the object. + Reference<lang::XComponent> xComponent (mxAccessibleShape, uno::UNO_QUERY); + if (xComponent.is()) + xComponent->dispose (); + + mxAccessibleShape = nullptr; } diff --git a/svx/source/accessibility/DescriptionGenerator.cxx b/svx/source/accessibility/DescriptionGenerator.cxx index 1716f999f1d6..d76918c218eb 100644 --- a/svx/source/accessibility/DescriptionGenerator.cxx +++ b/svx/source/accessibility/DescriptionGenerator.cxx @@ -69,35 +69,35 @@ void DescriptionGenerator::Initialize(const char* pResourceId) void DescriptionGenerator::Initialize (const OUString& sPrefix) { msDescription = sPrefix; - if (mxSet.is()) + if (!mxSet.is()) + return; + { - { - SolarMutexGuard aGuard; + SolarMutexGuard aGuard; - msDescription.append(' '); - msDescription.append(SvxResId(RID_SVXSTR_A11Y_WITH)); - msDescription.append(' '); + msDescription.append(' '); + msDescription.append(SvxResId(RID_SVXSTR_A11Y_WITH)); + msDescription.append(' '); - msDescription.append(SvxResId (RID_SVXSTR_A11Y_STYLE)); - msDescription.append('='); - } + msDescription.append(SvxResId (RID_SVXSTR_A11Y_STYLE)); + msDescription.append('='); + } - try - { - if (mxSet.is()) - { - uno::Any aValue = mxSet->getPropertyValue ("Style"); - uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY); - if (xStyle.is()) - msDescription.append (xStyle->getName()); - } - else - msDescription.append ("<no style>"); - } - catch (const css::beans::UnknownPropertyException &) + try + { + if (mxSet.is()) { - msDescription.append ("<unknown>"); + uno::Any aValue = mxSet->getPropertyValue ("Style"); + uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY); + if (xStyle.is()) + msDescription.append (xStyle->getName()); } + else + msDescription.append ("<no style>"); + } + catch (const css::beans::UnknownPropertyException &) + { + msDescription.append ("<unknown>"); } } @@ -113,34 +113,36 @@ void DescriptionGenerator::AddProperty (const OUString& sPropertyName, PropertyType aType) { uno::Reference<beans::XPropertyState> xState (mxShape, uno::UNO_QUERY); - if (xState.is() - && xState->getPropertyState(sPropertyName)!=beans::PropertyState_DEFAULT_VALUE) - if (mxSet.is()) - { - // Append a separator from previous Properties. - if ( ! mbIsFirstProperty) - msDescription.append(','); - else - { - SolarMutexGuard aGuard; - - msDescription.append(' '); - msDescription.append(SvxResId(RID_SVXSTR_A11Y_AND)); - msDescription.append(' '); - mbIsFirstProperty = false; - } - - // Delegate to type specific property handling. - switch (aType) - { - case PropertyType::Color: - AddColor (sPropertyName); - break; - case PropertyType::Integer: - AddInteger (sPropertyName); - break; - } - } + if (!xState.is() + || xState->getPropertyState(sPropertyName)==beans::PropertyState_DEFAULT_VALUE) + return; + + if (!mxSet.is()) + return; + + // Append a separator from previous Properties. + if ( ! mbIsFirstProperty) + msDescription.append(','); + else + { + SolarMutexGuard aGuard; + + msDescription.append(' '); + msDescription.append(SvxResId(RID_SVXSTR_A11Y_AND)); + msDescription.append(' '); + mbIsFirstProperty = false; + } + + // Delegate to type specific property handling. + switch (aType) + { + case PropertyType::Color: + AddColor (sPropertyName); + break; + case PropertyType::Integer: + AddInteger (sPropertyName); + break; + } } diff --git a/svx/source/accessibility/GraphCtlAccessibleContext.cxx b/svx/source/accessibility/GraphCtlAccessibleContext.cxx index 8d0c4dfc028a..5ef5801e90c1 100644 --- a/svx/source/accessibility/GraphCtlAccessibleContext.cxx +++ b/svx/source/accessibility/GraphCtlAccessibleContext.cxx @@ -445,20 +445,20 @@ void SAL_CALL SvxGraphCtrlAccessibleContext::addAccessibleEventListener( const R void SAL_CALL SvxGraphCtrlAccessibleContext::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener ) { - if (xListener.is()) - { - ::SolarMutexGuard aGuard; + if (!xListener.is()) + return; - sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener ); - if ( !nListenerCount ) - { - // no listeners anymore - // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client), - // and at least to us not firing any events anymore, in case somebody calls - // NotifyAccessibleEvent, again - comphelper::AccessibleEventNotifier::revokeClient( mnClientId ); - mnClientId = 0; - } + ::SolarMutexGuard aGuard; + + sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener ); + if ( !nListenerCount ) + { + // no listeners anymore + // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client), + // and at least to us not firing any events anymore, in case somebody calls + // NotifyAccessibleEvent, again + comphelper::AccessibleEventNotifier::revokeClient( mnClientId ); + mnClientId = 0; } } @@ -598,25 +598,25 @@ void SAL_CALL SvxGraphCtrlAccessibleContext::deselectAccessibleChild( sal_Int32 checkChildIndexOnSelection( nIndex ); - if( mpView ) - { - const SdrMarkList& rList = mpView->GetMarkedObjectList(); + if( !mpView ) + return; - SdrObject* pObj = getSdrObject( nIndex ); - if( pObj ) - { - SdrMarkList aRefList( rList ); + const SdrMarkList& rList = mpView->GetMarkedObjectList(); - SdrPageView* pPV = mpView->GetSdrPageView(); - mpView->UnmarkAllObj( pPV ); + SdrObject* pObj = getSdrObject( nIndex ); + if( !pObj ) + return; - const size_t nCount = aRefList.GetMarkCount(); - for( size_t nMark = 0; nMark < nCount; ++nMark ) - { - if( aRefList.GetMark(nMark)->GetMarkedSdrObj() != pObj ) - mpView->MarkObj( aRefList.GetMark(nMark)->GetMarkedSdrObj(), pPV ); - } - } + SdrMarkList aRefList( rList ); + + SdrPageView* pPV = mpView->GetSdrPageView(); + mpView->UnmarkAllObj( pPV ); + + const size_t nCount = aRefList.GetMarkCount(); + for( size_t nMark = 0; nMark < nCount; ++nMark ) + { + if( aRefList.GetMark(nMark)->GetMarkedSdrObj() != pObj ) + mpView->MarkObj( aRefList.GetMark(nMark)->GetMarkedSdrObj(), pPV ); } } diff --git a/svx/source/accessibility/lookupcolorname.cxx b/svx/source/accessibility/lookupcolorname.cxx index 58d88202644c..d8f75f45aae3 100644 --- a/svx/source/accessibility/lookupcolorname.cxx +++ b/svx/source/accessibility/lookupcolorname.cxx @@ -74,23 +74,25 @@ ColorNameMap::ColorNameMap() { } // Fill the map to convert from numerical color values to names. - if (xNA.is()) - for (const auto& rName : std::as_const(aNames)) + if (!xNA.is()) + return; + + for (const auto& rName : std::as_const(aNames)) + { + // Get the numerical value for the i-th color name. + try { - // Get the numerical value for the i-th color name. - try - { - css::uno::Any aColor = xNA->getByName(rName); - long nColor = 0; - aColor >>= nColor; - map_[nColor] = rName; - } - catch (css::uno::RuntimeException const&) - { - // Ignore the exception: the color who lead to the exception - // is not included into the map. - } + css::uno::Any aColor = xNA->getByName(rName); + long nColor = 0; + aColor >>= nColor; + map_[nColor] = rName; } + catch (css::uno::RuntimeException const&) + { + // Ignore the exception: the color who lead to the exception + // is not included into the map. + } + } } OUString ColorNameMap::lookUp(long color) const { diff --git a/svx/source/accessibility/svxrectctaccessiblecontext.cxx b/svx/source/accessibility/svxrectctaccessiblecontext.cxx index 1d767be13d91..00959017dd4d 100644 --- a/svx/source/accessibility/svxrectctaccessiblecontext.cxx +++ b/svx/source/accessibility/svxrectctaccessiblecontext.cxx @@ -333,31 +333,31 @@ void SvxRectCtlAccessibleContext::FireChildFocus( RectPoint eButton ) void SvxRectCtlAccessibleContext::selectChild( long nNew ) { ::osl::MutexGuard aGuard( m_aMutex ); - if( nNew != mnSelectedChild ) - { - long nNumOfChildren = getAccessibleChildCount(); - if( nNew < nNumOfChildren ) - { // valid index - SvxRectCtlChildAccessibleContext* pChild; - if( mnSelectedChild != NOCHILDSELECTED ) - { // deselect old selected child if one is selected - pChild = mvChildren[ mnSelectedChild ].get(); - if( pChild ) - pChild->setStateChecked( false ); - } - - // select new child - mnSelectedChild = nNew; - - if( nNew != NOCHILDSELECTED ) - { - if( mvChildren[ nNew ].is() ) - mvChildren[ nNew ]->setStateChecked( true ); - } + if( nNew == mnSelectedChild ) + return; + + long nNumOfChildren = getAccessibleChildCount(); + if( nNew < nNumOfChildren ) + { // valid index + SvxRectCtlChildAccessibleContext* pChild; + if( mnSelectedChild != NOCHILDSELECTED ) + { // deselect old selected child if one is selected + pChild = mvChildren[ mnSelectedChild ].get(); + if( pChild ) + pChild->setStateChecked( false ); + } + + // select new child + mnSelectedChild = nNew; + + if( nNew != NOCHILDSELECTED ) + { + if( mvChildren[ nNew ].is() ) + mvChildren[ nNew ]->setStateChecked( true ); } - else - mnSelectedChild = NOCHILDSELECTED; } + else + mnSelectedChild = NOCHILDSELECTED; } void SvxRectCtlAccessibleContext::selectChild(RectPoint eButton ) @@ -611,22 +611,22 @@ awt::Rectangle SvxRectCtlChildAccessibleContext::implGetBounds( ) void SvxRectCtlChildAccessibleContext::setStateChecked( bool bChecked ) { - if( mbIsChecked != bChecked ) - { - mbIsChecked = bChecked; + if( mbIsChecked == bChecked ) + return; + + mbIsChecked = bChecked; - Any aOld; - Any aNew; - Any& rMod = bChecked? aNew : aOld; + Any aOld; + Any aNew; + Any& rMod = bChecked? aNew : aOld; - //Send the STATE_CHANGED(Focused) event to accessible - rMod <<= AccessibleStateType::FOCUSED; - NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aOld, aNew); + //Send the STATE_CHANGED(Focused) event to accessible + rMod <<= AccessibleStateType::FOCUSED; + NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aOld, aNew); - rMod <<= AccessibleStateType::CHECKED; + rMod <<= AccessibleStateType::CHECKED; - NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aOld, aNew); - } + NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aOld, aNew); } void SvxRectCtlChildAccessibleContext::FireFocusEvent() |