sfx2/Library_sfx.mk | 1 sfx2/source/control/thumbnailview.cxx | 1 sfx2/source/control/thumbnailviewacc.cxx | 295 ----------------------- sfx2/source/control/thumbnailviewacc.hxx | 57 ---- sfx2/source/control/thumbnailviewitem.cxx | 2 sfx2/source/control/thumbnailviewitemacc.cxx | 335 +++++++++++++++++++++++++++ sfx2/source/control/thumbnailviewitemacc.hxx | 83 ++++++ solenv/clang-format/excludelist | 2 8 files changed, 425 insertions(+), 351 deletions(-)
New commits: commit 1c269af407824997139e73e79fb262725b51d83b Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Feb 26 10:42:28 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Feb 26 20:09:24 2025 +0100 thumbnailview a11y: Use #pragma once Change-Id: Icbb74ea2279c0c31d827a20e61847e77af0bcbe1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182216 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/sfx2/source/control/thumbnailviewacc.hxx b/sfx2/source/control/thumbnailviewacc.hxx index 18270099c79a..9184bfdb0149 100644 --- a/sfx2/source/control/thumbnailviewacc.hxx +++ b/sfx2/source/control/thumbnailviewacc.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SFX2_SOURCE_CONTROL_THUMBNAILVIEWACC_HXX -#define INCLUDED_SFX2_SOURCE_CONTROL_THUMBNAILVIEWACC_HXX +#pragma once #include <cppuhelper/implbase.hxx> #include <comphelper/compbase.hxx> @@ -145,6 +144,4 @@ private: void ThrowIfDisposed(); }; -#endif // INCLUDED_SFX2_SOURCE_CONTROL_THUMBNAILVIEWACC_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 4cc1949e366902aea2de6c0118dd1432d914baca Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Feb 26 10:34:57 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Feb 26 20:09:18 2025 +0100 thumbnailview a11y: Don't confuse x/y pos for item location Fix ThumbnailViewItemAcc::getLocationOnScreen by using the y coordinate of the parent's screen position instead of the x one when calculating the item's y position. This makes Accerciser highlight the correct area on screen when selecting the a11y object of one of the recent documents in the "Recent Documents" tab in the LO Start Center. Change-Id: I34ad1797e042d93bebf8dca1025c914db6dda254 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182211 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/sfx2/source/control/thumbnailviewitemacc.cxx b/sfx2/source/control/thumbnailviewitemacc.cxx index dbefdb35fea2..3b22f82141d1 100644 --- a/sfx2/source/control/thumbnailviewitemacc.cxx +++ b/sfx2/source/control/thumbnailviewitemacc.cxx @@ -299,7 +299,7 @@ awt::Point SAL_CALL ThumbnailViewItemAcc::getLocationOnScreen() mpThumbnailViewItem->mrParent.GetDrawingArea()->get_accessible_location_on_screen()); aRet.X = aPos.X() + aScreenPos.X(); - aRet.Y = aPos.Y() + aScreenPos.X(); + aRet.Y = aPos.Y() + aScreenPos.Y(); } return aRet; commit 6b94da5baa8d75c709877807d6057309d9a3678f Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Feb 26 10:18:05 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Feb 26 20:09:12 2025 +0100 thumbnailview acc: Move ThumbnailViewItemAcc to own .hxx/.cxx Change-Id: If9a7f674488f16480bcf09e3dcfa084b42b350e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182210 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index a55494e38f00..66e51be7f87e 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -163,6 +163,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/control/listview \ sfx2/source/control/thumbnailviewitem \ sfx2/source/control/thumbnailviewacc \ + sfx2/source/control/thumbnailviewitemacc \ sfx2/source/control/thumbnailview \ sfx2/source/control/charmapcontrol \ sfx2/source/control/charwin \ diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index 26538e0efc21..488264fccdbc 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -15,6 +15,7 @@ #include <utility> #include "thumbnailviewacc.hxx" +#include "thumbnailviewitemacc.hxx" #include <basegfx/color/bcolortools.hxx> #include <comphelper/processfactory.hxx> diff --git a/sfx2/source/control/thumbnailviewacc.cxx b/sfx2/source/control/thumbnailviewacc.cxx index faa27ac0cb88..3315cb050354 100644 --- a/sfx2/source/control/thumbnailviewacc.cxx +++ b/sfx2/source/control/thumbnailviewacc.cxx @@ -18,6 +18,7 @@ */ #include "thumbnailviewacc.hxx" +#include "thumbnailviewitemacc.hxx" #include <comphelper/servicehelper.hxx> #include <sfx2/thumbnailview.hxx> @@ -493,21 +494,6 @@ void ThumbnailViewAcc::ThrowIfDisposed() } } -ThumbnailViewItemAcc::ThumbnailViewItemAcc(ThumbnailViewItem* pThumbnailViewItem) - : mpThumbnailViewItem(pThumbnailViewItem) -{ -} - -ThumbnailViewItemAcc::~ThumbnailViewItemAcc() -{ -} - -void ThumbnailViewItemAcc::ThumbnailViewItemDestroyed() -{ - std::scoped_lock aGuard( maMutex ); - mpThumbnailViewItem = nullptr; -} - void ThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue ) { if( !nEventId ) @@ -556,283 +542,4 @@ void ThumbnailViewAcc::LoseFocus() aOldState, aNewState); } -uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewItemAcc::getAccessibleContext() -{ - return this; -} - -sal_Int64 SAL_CALL ThumbnailViewItemAcc::getAccessibleChildCount() -{ - return 0; -} - -uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleChild( sal_Int64 ) -{ - throw lang::IndexOutOfBoundsException(); -} - -uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleParent() -{ - const SolarMutexGuard aSolarGuard; - uno::Reference< accessibility::XAccessible > xRet; - - if (mpThumbnailViewItem) - xRet = mpThumbnailViewItem->mrParent.getAccessible(); - - return xRet; -} - -sal_Int64 SAL_CALL ThumbnailViewItemAcc::getAccessibleIndexInParent() -{ - const SolarMutexGuard aSolarGuard; - // The index defaults to -1 to indicate the child does not belong to its - // parent. - sal_Int64 nIndexInParent = -1; - - if (mpThumbnailViewItem) - { - bool bDone = false; - - sal_uInt16 nCount = mpThumbnailViewItem->mrParent.ImplGetVisibleItemCount(); - ThumbnailViewItem* pItem; - for (sal_uInt16 i=0; i<nCount && !bDone; i++) - { - // Guard the retrieval of the i-th child with a try/catch block - // just in case the number of children changes in the meantime. - try - { - pItem = mpThumbnailViewItem->mrParent.ImplGetVisibleItem(i); - } - catch (const lang::IndexOutOfBoundsException&) - { - pItem = nullptr; - } - - if (pItem && pItem == mpThumbnailViewItem) - { - nIndexInParent = i; - bDone = true; - } - } - } - - return nIndexInParent; -} - -sal_Int16 SAL_CALL ThumbnailViewItemAcc::getAccessibleRole() -{ - return accessibility::AccessibleRole::LIST_ITEM; -} - -OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleDescription() -{ - return OUString(); -} - -OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleName() -{ - const SolarMutexGuard aSolarGuard; - OUString aRet; - - if (mpThumbnailViewItem) - { - aRet = mpThumbnailViewItem->maTitle; - - if( aRet.isEmpty() ) - { - aRet = "Item " + OUString::number(static_cast<sal_Int32>(mpThumbnailViewItem->mnId)); - } - } - - return aRet; -} - -uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleRelationSet() -{ - return uno::Reference< accessibility::XAccessibleRelationSet >(); -} - -sal_Int64 SAL_CALL ThumbnailViewItemAcc::getAccessibleStateSet() -{ - const SolarMutexGuard aSolarGuard; - sal_Int64 nStateSet = 0; - - if (mpThumbnailViewItem) - { - nStateSet |= accessibility::AccessibleStateType::ENABLED; - nStateSet |= accessibility::AccessibleStateType::SENSITIVE; - nStateSet |= accessibility::AccessibleStateType::SHOWING; - nStateSet |= accessibility::AccessibleStateType::VISIBLE; - nStateSet |= accessibility::AccessibleStateType::TRANSIENT; - nStateSet |= accessibility::AccessibleStateType::SELECTABLE; - nStateSet |= accessibility::AccessibleStateType::FOCUSABLE; - - if (mpThumbnailViewItem->isSelected()) - { - nStateSet |= accessibility::AccessibleStateType::SELECTED; - if (mpThumbnailViewItem->mrParent.HasChildFocus()) - nStateSet |= accessibility::AccessibleStateType::FOCUSED; - } - } - - return nStateSet; -} - -lang::Locale SAL_CALL ThumbnailViewItemAcc::getLocale() -{ - const SolarMutexGuard aSolarGuard; - uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() ); - lang::Locale aRet( u""_ustr, u""_ustr, u""_ustr ); - - if( xParent.is() ) - { - uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() ); - - if( xParentContext.is() ) - aRet = xParentContext->getLocale(); - } - - return aRet; -} - -void SAL_CALL ThumbnailViewItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - std::scoped_lock aGuard( maMutex ); - - if( !rxListener.is() ) - return; - - bool bFound = false; - - for (auto const& eventListener : mxEventListeners) - { - if( eventListener == rxListener ) - { - bFound = true; - break; - } - } - - if (!bFound) - mxEventListeners.push_back( rxListener ); -} - -void SAL_CALL ThumbnailViewItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - std::scoped_lock aGuard( maMutex ); - - if( rxListener.is() ) - { - std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = - std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener); - - if (aIter != mxEventListeners.end()) - mxEventListeners.erase( aIter ); - } -} - -sal_Bool SAL_CALL ThumbnailViewItemAcc::containsPoint( const awt::Point& aPoint ) -{ - const awt::Rectangle aRect( getBounds() ); - const Point aSize( aRect.Width, aRect.Height ); - const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y ); - - return tools::Rectangle( aNullPoint, aSize ).Contains( aTestPoint ); -} - -uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleAtPoint( const awt::Point& ) -{ - uno::Reference< accessibility::XAccessible > xRet; - return xRet; -} - -awt::Rectangle SAL_CALL ThumbnailViewItemAcc::getBounds() -{ - const SolarMutexGuard aSolarGuard; - awt::Rectangle aRet; - - if (mpThumbnailViewItem) - { - tools::Rectangle aRect(mpThumbnailViewItem->getDrawArea()); - tools::Rectangle aParentRect; - - // get position of the accessible parent in screen coordinates - uno::Reference< XAccessible > xParent = getAccessibleParent(); - if ( xParent.is() ) - { - uno::Reference<XAccessibleComponent> xParentComponent(xParent->getAccessibleContext(), uno::UNO_QUERY); - if (xParentComponent.is()) - { - awt::Size aParentSize = xParentComponent->getSize(); - aParentRect = tools::Rectangle(0, 0, aParentSize.Width, aParentSize.Height); - } - } - - aRect.Intersection( aParentRect ); - - aRet.X = aRect.Left(); - aRet.Y = aRect.Top(); - aRet.Width = aRect.GetWidth(); - aRet.Height = aRect.GetHeight(); - } - - return aRet; -} - -awt::Point SAL_CALL ThumbnailViewItemAcc::getLocation() -{ - const awt::Rectangle aRect( getBounds() ); - awt::Point aRet; - - aRet.X = aRect.X; - aRet.Y = aRect.Y; - - return aRet; -} - -awt::Point SAL_CALL ThumbnailViewItemAcc::getLocationOnScreen() -{ - const SolarMutexGuard aSolarGuard; - awt::Point aRet; - - if (mpThumbnailViewItem) - { - const Point aPos = mpThumbnailViewItem->getDrawArea().TopLeft(); - const Point aScreenPos( - mpThumbnailViewItem->mrParent.GetDrawingArea()->get_accessible_location_on_screen()); - - aRet.X = aPos.X() + aScreenPos.X(); - aRet.Y = aPos.Y() + aScreenPos.X(); - } - - return aRet; -} - -awt::Size SAL_CALL ThumbnailViewItemAcc::getSize() -{ - const awt::Rectangle aRect( getBounds() ); - awt::Size aRet; - - aRet.Width = aRect.Width; - aRet.Height = aRect.Height; - - return aRet; -} - -void SAL_CALL ThumbnailViewItemAcc::grabFocus() -{ - // nothing to do -} - -sal_Int32 SAL_CALL ThumbnailViewItemAcc::getForeground( ) -{ - Color nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor(); - return static_cast<sal_Int32>(nColor); -} - -sal_Int32 SAL_CALL ThumbnailViewItemAcc::getBackground( ) -{ - return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetWindowColor()); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/thumbnailviewacc.hxx b/sfx2/source/control/thumbnailviewacc.hxx index 22c4d2464c11..18270099c79a 100644 --- a/sfx2/source/control/thumbnailviewacc.hxx +++ b/sfx2/source/control/thumbnailviewacc.hxx @@ -145,58 +145,6 @@ private: void ThrowIfDisposed(); }; - -class ThumbnailViewItemAcc : public ::cppu::WeakImplHelper< css::accessibility::XAccessible, - css::accessibility::XAccessibleEventBroadcaster, - css::accessibility::XAccessibleContext, - css::accessibility::XAccessibleComponent> -{ -private: - - ::std::vector< css::uno::Reference< css::accessibility::XAccessibleEventListener > > - mxEventListeners; - std::mutex maMutex; - ThumbnailViewItem* mpThumbnailViewItem; - -public: - ThumbnailViewItemAcc(ThumbnailViewItem* pThumbnailViewItem); - virtual ~ThumbnailViewItemAcc() override; - - void ThumbnailViewItemDestroyed(); - -public: - - // XAccessible - virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override; - - // XAccessibleEventBroadcaster - virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; - virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; - - // XAccessibleContext - virtual sal_Int64 SAL_CALL getAccessibleChildCount( ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 i ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override; - virtual sal_Int64 SAL_CALL getAccessibleIndexInParent( ) override; - virtual sal_Int16 SAL_CALL getAccessibleRole( ) override; - virtual OUString SAL_CALL getAccessibleDescription( ) override; - virtual OUString SAL_CALL getAccessibleName( ) override; - virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override; - virtual sal_Int64 SAL_CALL getAccessibleStateSet( ) override; - virtual css::lang::Locale SAL_CALL getLocale( ) override; - - // XAccessibleComponent - virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override; - virtual css::awt::Rectangle SAL_CALL getBounds( ) override; - virtual css::awt::Point SAL_CALL getLocation( ) override; - virtual css::awt::Point SAL_CALL getLocationOnScreen( ) override; - virtual css::awt::Size SAL_CALL getSize( ) override; - virtual void SAL_CALL grabFocus( ) override; - virtual sal_Int32 SAL_CALL getForeground( ) override; - virtual sal_Int32 SAL_CALL getBackground( ) override; -}; - #endif // INCLUDED_SFX2_SOURCE_CONTROL_THUMBNAILVIEWACC_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx index ed4ffb03b24b..9827b2a62669 100644 --- a/sfx2/source/control/thumbnailviewitem.cxx +++ b/sfx2/source/control/thumbnailviewitem.cxx @@ -19,7 +19,7 @@ #include <sfx2/thumbnailviewitem.hxx> #include <sfx2/thumbnailview.hxx> -#include "thumbnailviewacc.hxx" +#include "thumbnailviewitemacc.hxx" #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/polygon/b2dpolygon.hxx> diff --git a/sfx2/source/control/thumbnailviewitemacc.cxx b/sfx2/source/control/thumbnailviewitemacc.cxx new file mode 100644 index 000000000000..dbefdb35fea2 --- /dev/null +++ b/sfx2/source/control/thumbnailviewitemacc.cxx @@ -0,0 +1,335 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "thumbnailviewacc.hxx" +#include "thumbnailviewitemacc.hxx" + +#include <comphelper/diagnose_ex.hxx> +#include <comphelper/servicehelper.hxx> +#include <sfx2/thumbnailview.hxx> +#include <sfx2/thumbnailviewitem.hxx> +#include <vcl/svapp.hxx> +#include <vcl/settings.hxx> +#include <sal/log.hxx> +#include <tools/debug.hxx> + +#include <com/sun/star/accessibility/AccessibleEventId.hpp> +#include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <com/sun/star/accessibility/AccessibleStateType.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> + +#include <mutex> + +using namespace ::com::sun::star; + +ThumbnailViewItemAcc::ThumbnailViewItemAcc(ThumbnailViewItem* pThumbnailViewItem) + : mpThumbnailViewItem(pThumbnailViewItem) +{ +} + +ThumbnailViewItemAcc::~ThumbnailViewItemAcc() +{ +} + +void ThumbnailViewItemAcc::ThumbnailViewItemDestroyed() +{ + std::scoped_lock aGuard( maMutex ); + mpThumbnailViewItem = nullptr; +} + +uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewItemAcc::getAccessibleContext() +{ + return this; +} + +sal_Int64 SAL_CALL ThumbnailViewItemAcc::getAccessibleChildCount() +{ + return 0; +} + +uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleChild( sal_Int64 ) +{ + throw lang::IndexOutOfBoundsException(); +} + +uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleParent() +{ + const SolarMutexGuard aSolarGuard; + uno::Reference< accessibility::XAccessible > xRet; + + if (mpThumbnailViewItem) + xRet = mpThumbnailViewItem->mrParent.getAccessible(); + + return xRet; +} + +sal_Int64 SAL_CALL ThumbnailViewItemAcc::getAccessibleIndexInParent() +{ + const SolarMutexGuard aSolarGuard; + // The index defaults to -1 to indicate the child does not belong to its + // parent. + sal_Int64 nIndexInParent = -1; + + if (mpThumbnailViewItem) + { + bool bDone = false; + + sal_uInt16 nCount = mpThumbnailViewItem->mrParent.ImplGetVisibleItemCount(); + ThumbnailViewItem* pItem; + for (sal_uInt16 i=0; i<nCount && !bDone; i++) + { + // Guard the retrieval of the i-th child with a try/catch block + // just in case the number of children changes in the meantime. + try + { + pItem = mpThumbnailViewItem->mrParent.ImplGetVisibleItem(i); + } + catch (const lang::IndexOutOfBoundsException&) + { + pItem = nullptr; + } + + if (pItem && pItem == mpThumbnailViewItem) + { + nIndexInParent = i; + bDone = true; + } + } + } + + return nIndexInParent; +} + +sal_Int16 SAL_CALL ThumbnailViewItemAcc::getAccessibleRole() +{ + return accessibility::AccessibleRole::LIST_ITEM; +} + +OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleDescription() +{ + return OUString(); +} + +OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleName() +{ + const SolarMutexGuard aSolarGuard; + OUString aRet; + + if (mpThumbnailViewItem) + { + aRet = mpThumbnailViewItem->maTitle; + + if( aRet.isEmpty() ) + { + aRet = "Item " + OUString::number(static_cast<sal_Int32>(mpThumbnailViewItem->mnId)); + } + } + + return aRet; +} + +uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleRelationSet() +{ + return uno::Reference< accessibility::XAccessibleRelationSet >(); +} + +sal_Int64 SAL_CALL ThumbnailViewItemAcc::getAccessibleStateSet() +{ + const SolarMutexGuard aSolarGuard; + sal_Int64 nStateSet = 0; + + if (mpThumbnailViewItem) + { + nStateSet |= accessibility::AccessibleStateType::ENABLED; + nStateSet |= accessibility::AccessibleStateType::SENSITIVE; + nStateSet |= accessibility::AccessibleStateType::SHOWING; + nStateSet |= accessibility::AccessibleStateType::VISIBLE; + nStateSet |= accessibility::AccessibleStateType::TRANSIENT; + nStateSet |= accessibility::AccessibleStateType::SELECTABLE; + nStateSet |= accessibility::AccessibleStateType::FOCUSABLE; + + if (mpThumbnailViewItem->isSelected()) + { + nStateSet |= accessibility::AccessibleStateType::SELECTED; + if (mpThumbnailViewItem->mrParent.HasChildFocus()) + nStateSet |= accessibility::AccessibleStateType::FOCUSED; + } + } + + return nStateSet; +} + +lang::Locale SAL_CALL ThumbnailViewItemAcc::getLocale() +{ + const SolarMutexGuard aSolarGuard; + uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() ); + lang::Locale aRet( u""_ustr, u""_ustr, u""_ustr ); + + if( xParent.is() ) + { + uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() ); + + if( xParentContext.is() ) + aRet = xParentContext->getLocale(); + } + + return aRet; +} + +void SAL_CALL ThumbnailViewItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) +{ + std::scoped_lock aGuard( maMutex ); + + if( !rxListener.is() ) + return; + + bool bFound = false; + + for (auto const& eventListener : mxEventListeners) + { + if( eventListener == rxListener ) + { + bFound = true; + break; + } + } + + if (!bFound) + mxEventListeners.push_back( rxListener ); +} + +void SAL_CALL ThumbnailViewItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) +{ + std::scoped_lock aGuard( maMutex ); + + if( rxListener.is() ) + { + std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = + std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener); + + if (aIter != mxEventListeners.end()) + mxEventListeners.erase( aIter ); + } +} + +sal_Bool SAL_CALL ThumbnailViewItemAcc::containsPoint( const awt::Point& aPoint ) +{ + const awt::Rectangle aRect( getBounds() ); + const Point aSize( aRect.Width, aRect.Height ); + const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y ); + + return tools::Rectangle( aNullPoint, aSize ).Contains( aTestPoint ); +} + +uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleAtPoint( const awt::Point& ) +{ + uno::Reference< accessibility::XAccessible > xRet; + return xRet; +} + +awt::Rectangle SAL_CALL ThumbnailViewItemAcc::getBounds() +{ + const SolarMutexGuard aSolarGuard; + awt::Rectangle aRet; + + if (mpThumbnailViewItem) + { + tools::Rectangle aRect(mpThumbnailViewItem->getDrawArea()); + tools::Rectangle aParentRect; + + // get position of the accessible parent in screen coordinates + uno::Reference< XAccessible > xParent = getAccessibleParent(); + if ( xParent.is() ) + { + uno::Reference<XAccessibleComponent> xParentComponent(xParent->getAccessibleContext(), uno::UNO_QUERY); + if (xParentComponent.is()) + { + awt::Size aParentSize = xParentComponent->getSize(); + aParentRect = tools::Rectangle(0, 0, aParentSize.Width, aParentSize.Height); + } + } + + aRect.Intersection( aParentRect ); + + aRet.X = aRect.Left(); + aRet.Y = aRect.Top(); + aRet.Width = aRect.GetWidth(); + aRet.Height = aRect.GetHeight(); + } + + return aRet; +} + +awt::Point SAL_CALL ThumbnailViewItemAcc::getLocation() +{ + const awt::Rectangle aRect( getBounds() ); + awt::Point aRet; + + aRet.X = aRect.X; + aRet.Y = aRect.Y; + + return aRet; +} + +awt::Point SAL_CALL ThumbnailViewItemAcc::getLocationOnScreen() +{ + const SolarMutexGuard aSolarGuard; + awt::Point aRet; + + if (mpThumbnailViewItem) + { + const Point aPos = mpThumbnailViewItem->getDrawArea().TopLeft(); + const Point aScreenPos( + mpThumbnailViewItem->mrParent.GetDrawingArea()->get_accessible_location_on_screen()); + + aRet.X = aPos.X() + aScreenPos.X(); + aRet.Y = aPos.Y() + aScreenPos.X(); + } + + return aRet; +} + +awt::Size SAL_CALL ThumbnailViewItemAcc::getSize() +{ + const awt::Rectangle aRect( getBounds() ); + awt::Size aRet; + + aRet.Width = aRect.Width; + aRet.Height = aRect.Height; + + return aRet; +} + +void SAL_CALL ThumbnailViewItemAcc::grabFocus() +{ + // nothing to do +} + +sal_Int32 SAL_CALL ThumbnailViewItemAcc::getForeground( ) +{ + Color nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor(); + return static_cast<sal_Int32>(nColor); +} + +sal_Int32 SAL_CALL ThumbnailViewItemAcc::getBackground( ) +{ + return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetWindowColor()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/thumbnailviewitemacc.hxx b/sfx2/source/control/thumbnailviewitemacc.hxx new file mode 100644 index 000000000000..ff342f698675 --- /dev/null +++ b/sfx2/source/control/thumbnailviewitemacc.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <cppuhelper/implbase.hxx> + +#include <com/sun/star/accessibility/XAccessible.hpp> +#include <com/sun/star/accessibility/XAccessibleContext.hpp> +#include <com/sun/star/accessibility/XAccessibleComponent.hpp> +#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> + +#include <vector> + +class ThumbnailViewItem; +class ThumbnailViewItemAcc : public ::cppu::WeakImplHelper< css::accessibility::XAccessible, + css::accessibility::XAccessibleEventBroadcaster, + css::accessibility::XAccessibleContext, + css::accessibility::XAccessibleComponent> +{ +private: + + ::std::vector< css::uno::Reference< css::accessibility::XAccessibleEventListener > > + mxEventListeners; + std::mutex maMutex; + ThumbnailViewItem* mpThumbnailViewItem; + +public: + ThumbnailViewItemAcc(ThumbnailViewItem* pThumbnailViewItem); + virtual ~ThumbnailViewItemAcc() override; + + void ThumbnailViewItemDestroyed(); + +public: + + // XAccessible + virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override; + + // XAccessibleEventBroadcaster + virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; + virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; + + // XAccessibleContext + virtual sal_Int64 SAL_CALL getAccessibleChildCount( ) override; + virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 i ) override; + virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override; + virtual sal_Int64 SAL_CALL getAccessibleIndexInParent( ) override; + virtual sal_Int16 SAL_CALL getAccessibleRole( ) override; + virtual OUString SAL_CALL getAccessibleDescription( ) override; + virtual OUString SAL_CALL getAccessibleName( ) override; + virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override; + virtual sal_Int64 SAL_CALL getAccessibleStateSet( ) override; + virtual css::lang::Locale SAL_CALL getLocale( ) override; + + // XAccessibleComponent + virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) override; + virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override; + virtual css::awt::Rectangle SAL_CALL getBounds( ) override; + virtual css::awt::Point SAL_CALL getLocation( ) override; + virtual css::awt::Point SAL_CALL getLocationOnScreen( ) override; + virtual css::awt::Size SAL_CALL getSize( ) override; + virtual void SAL_CALL grabFocus( ) override; + virtual sal_Int32 SAL_CALL getForeground( ) override; + virtual sal_Int32 SAL_CALL getBackground( ) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index e0dbabc2be18..638a5b1ecd20 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -10130,6 +10130,8 @@ sfx2/source/control/templateviewitem.cxx sfx2/source/control/thumbnailview.cxx sfx2/source/control/thumbnailviewacc.cxx sfx2/source/control/thumbnailviewacc.hxx +sfx2/source/control/thumbnailviewitemacc.cxx +sfx2/source/control/thumbnailviewitemacc.hxx sfx2/source/control/thumbnailviewitem.cxx sfx2/source/control/unoctitm.cxx sfx2/source/dialog/backingcomp.cxx