chart2/source/controller/accessibility/AccessibleBase.cxx | 3 chart2/source/controller/accessibility/AccessibleChartElement.cxx | 2 chart2/source/controller/accessibility/AccessibleChartShape.cxx | 2 chart2/source/controller/accessibility/AccessibleChartView.cxx | 65 ++++------ chart2/source/controller/accessibility/AccessibleTextHelper.cxx | 4 chart2/source/controller/inc/AccessibleBase.hxx | 3 chart2/source/controller/inc/AccessibleChartView.hxx | 11 - chart2/source/controller/inc/AccessibleTextHelper.hxx | 5 chart2/source/controller/main/ChartController.cxx | 14 +- 9 files changed, 53 insertions(+), 56 deletions(-)
New commits: commit a97b5966d3b2e6ff40d945ec94eafa4176d53753 Author: Michael Weghorn <[email protected]> AuthorDate: Mon Mar 31 07:08:39 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Apr 1 11:18:40 2025 +0200 chart a11y: use vcl::Window instead of XWindow Switch AccessibleChartView::m_xWindow, AccessibleElementInfo::m_xWindow and related code from using the UNO interface css::uno::WeakReference<css::awt::XWindow> to using the concrete implementation class vcl::Window/ChartWindow directly instead of assuming it's a vcl::Window and then using VCLUnoHelper::GetWindow to get the vcl::Window from the XWindow in multiple places. Rename the members accordingly. Use a VclPtr and clear it in AccessibleBase::disposing and AccessibleChartView::disposing. No change in behavior intended or seen in a quick test using Accerciser with the qt6 VCL plugin with a chart inserted in Writer using "Insert" -> "Chart". Change-Id: If98ef041fdd1a8bf68620e0c8b1e81973e7b01f5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183522 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/chart2/source/controller/accessibility/AccessibleBase.cxx b/chart2/source/controller/accessibility/AccessibleBase.cxx index 3a0fda2152b6..98bc1d7e1d40 100644 --- a/chart2/source/controller/accessibility/AccessibleBase.cxx +++ b/chart2/source/controller/accessibility/AccessibleBase.cxx @@ -393,6 +393,7 @@ void SAL_CALL AccessibleBase::disposing() } // reset pointers + m_aAccInfo.m_pWindow.clear(); m_aAccInfo.m_pParent = nullptr; m_nStateSet = AccessibleStateType::DEFUNC; @@ -596,7 +597,7 @@ awt::Rectangle SAL_CALL AccessibleBase::getBounds() rtl::Reference<ChartView> pChartView = m_aAccInfo.m_xView.get(); if( pChartView ) { - VclPtr<vcl::Window> pWindow( VCLUnoHelper::GetWindow( m_aAccInfo.m_xWindow )); + VclPtr<vcl::Window> pWindow = m_aAccInfo.m_pWindow; awt::Rectangle aLogicRect( pChartView->getRectangleOfObject( m_aAccInfo.m_aOID.getObjectCID() )); if( pWindow ) { diff --git a/chart2/source/controller/accessibility/AccessibleChartElement.cxx b/chart2/source/controller/accessibility/AccessibleChartElement.cxx index adec462c4db3..e176846b8b84 100644 --- a/chart2/source/controller/accessibility/AccessibleChartElement.cxx +++ b/chart2/source/controller/accessibility/AccessibleChartElement.cxx @@ -88,7 +88,7 @@ void AccessibleChartElement::InitTextEdit() if( !m_xTextHelper.is()) return; - m_xTextHelper->initialize( GetInfo().m_aOID.getObjectCID(), this, GetInfo().m_xWindow ); + m_xTextHelper->initialize(GetInfo().m_aOID.getObjectCID(), this, GetInfo().m_pWindow); } // Interfaces diff --git a/chart2/source/controller/accessibility/AccessibleChartShape.cxx b/chart2/source/controller/accessibility/AccessibleChartShape.cxx index 6d573762eb95..c37580a7d2c1 100644 --- a/chart2/source/controller/accessibility/AccessibleChartShape.cxx +++ b/chart2/source/controller/accessibility/AccessibleChartShape.cxx @@ -50,7 +50,7 @@ AccessibleChartShape::AccessibleChartShape( m_aShapeTreeInfo.SetSdrView( rAccInfo.m_pSdrView ); m_aShapeTreeInfo.SetController( nullptr ); - m_aShapeTreeInfo.SetWindow( VCLUnoHelper::GetWindow( rAccInfo.m_xWindow ) ); + m_aShapeTreeInfo.SetWindow(rAccInfo.m_pWindow); m_aShapeTreeInfo.SetViewForwarder( rAccInfo.m_pViewForwarder ); ::accessibility::ShapeTypeHandler& rShapeHandler = ::accessibility::ShapeTypeHandler::Instance(); diff --git a/chart2/source/controller/accessibility/AccessibleChartView.cxx b/chart2/source/controller/accessibility/AccessibleChartView.cxx index 0a4e02e64237..57d5d962cd5a 100644 --- a/chart2/source/controller/accessibility/AccessibleChartView.cxx +++ b/chart2/source/controller/accessibility/AccessibleChartView.cxx @@ -64,20 +64,19 @@ AccessibleChartView::~AccessibleChartView() awt::Rectangle AccessibleChartView::GetWindowPosSize() const { - Reference< awt::XWindow > xWindow( GetInfo().m_xWindow ); - if( ! xWindow.is()) - return awt::Rectangle(); + SolarMutexGuard aSolarGuard; - awt::Rectangle aBBox( xWindow->getPosSize() ); + VclPtr<vcl::Window> pWindow = GetInfo().m_pWindow; + if (!pWindow) + return awt::Rectangle(); - VclPtr<vcl::Window> pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow )); - if( pWindow ) - { - SolarMutexGuard aSolarGuard; - Point aVCLPoint( pWindow->OutputToAbsoluteScreenPixel( Point( 0, 0 ) )); - aBBox.X = aVCLPoint.getX(); - aBBox.Y = aVCLPoint.getY(); - } + awt::Rectangle aBBox; + Point aVCLPoint( pWindow->OutputToAbsoluteScreenPixel( Point( 0, 0 ) )); + const Size aSize = pWindow->GetSizePixel(); + aBBox.X = aVCLPoint.getX(); + aBBox.Y = aVCLPoint.getY(); + aBBox.Width = aSize.Width(); + aBBox.Height = aSize.Height(); return aBBox; } @@ -154,11 +153,18 @@ awt::Point SAL_CALL AccessibleChartView::getLocationOnScreen() return aResult; } +void SAL_CALL AccessibleChartView::disposing() +{ + m_pChartWindow.clear(); + + AccessibleBase::disposing(); +} + void AccessibleChartView::initialize( ChartController& rNewChartController, const rtl::Reference<::chart::ChartModel>& xNewChartModel, const rtl::Reference<::chart::ChartView>& xNewChartView, const uno::Reference< XAccessible >& xNewParent, - const css::uno::Reference<css::awt::XWindow>& xNewWindow ) + ChartWindow* pNewChartWindow) { //0: view::XSelectionSupplier offers notifications for selection changes and access to the selection itself //1: frame::XModel representing the chart model - offers access to object data @@ -173,14 +179,14 @@ void AccessibleChartView::initialize( ChartController& rNewChartController, rtl::Reference<::chart::ChartModel> xChartModel; rtl::Reference<::chart::ChartView> xChartView; Reference< XAccessible > xParent; - Reference< awt::XWindow > xWindow; + VclPtr<ChartWindow> pChartWindow; { MutexGuard aGuard( m_aMutex); xChartController = m_xChartController; xChartModel = m_xChartModel; xChartView = m_xChartView; xParent.set( m_xParent ); - xWindow.set( m_xWindow ); + pChartWindow = m_pChartWindow; } if( !xChartController.is() || !xChartModel.is() || !xChartView.is() ) @@ -206,9 +212,9 @@ void AccessibleChartView::initialize( ChartController& rNewChartController, bChanged = true; } - if( xNewWindow != xWindow ) + if (pNewChartWindow != pChartWindow) { - xWindow = xNewWindow; + pChartWindow = pNewChartWindow; bChanged = true; } @@ -231,7 +237,7 @@ void AccessibleChartView::initialize( ChartController& rNewChartController, xChartModel.clear(); xChartView.clear(); xParent.clear(); - xWindow.clear(); + pChartWindow.clear(); bNewInvalid = true; } @@ -242,7 +248,7 @@ void AccessibleChartView::initialize( ChartController& rNewChartController, m_xChartModel = xChartModel.get(); m_xChartView = xChartView.get(); m_xParent = xParent; - m_xWindow = xWindow; + m_pChartWindow = pChartWindow; } if( bOldInvalid && bNewInvalid ) @@ -268,12 +274,11 @@ void AccessibleChartView::initialize( ChartController& rNewChartController, aAccInfo.m_xChartDocument = m_xChartModel; aAccInfo.m_xChartController = m_xChartController; aAccInfo.m_xView = m_xChartView; - aAccInfo.m_xWindow = m_xWindow; + aAccInfo.m_pWindow = m_pChartWindow; aAccInfo.m_pParent = nullptr; aAccInfo.m_spObjectHierarchy = m_spObjectHierarchy; aAccInfo.m_pSdrView = m_pSdrView; - VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( m_xWindow ); - m_pViewForwarder.reset( new AccessibleViewForwarder( this, pWindow ) ); + m_pViewForwarder.reset(new AccessibleViewForwarder(this, m_pChartWindow)); aAccInfo.m_pViewForwarder = m_pViewForwarder.get(); // broadcasts an INVALIDATE_ALL_CHILDREN event globally SetInfo( aAccInfo ); @@ -330,7 +335,7 @@ void AccessibleChartView::initialize() m_xChartModel = xChartModel.get(); m_xChartView = xChartView.get(); m_xParent.clear(); - m_xWindow.clear(); + m_pChartWindow.clear(); } if( bOldInvalid ) @@ -356,7 +361,7 @@ void AccessibleChartView::initialize() aAccInfo.m_xChartDocument = m_xChartModel; aAccInfo.m_xChartController = m_xChartController; aAccInfo.m_xView = m_xChartView; - aAccInfo.m_xWindow = css::uno::WeakReference<css::awt::XWindow>(nullptr); + aAccInfo.m_pWindow.clear(); aAccInfo.m_pParent = nullptr; aAccInfo.m_spObjectHierarchy = m_spObjectHierarchy; aAccInfo.m_pSdrView = m_pSdrView; diff --git a/chart2/source/controller/accessibility/AccessibleTextHelper.cxx b/chart2/source/controller/accessibility/AccessibleTextHelper.cxx index a117186f4521..15112a674a83 100644 --- a/chart2/source/controller/accessibility/AccessibleTextHelper.cxx +++ b/chart2/source/controller/accessibility/AccessibleTextHelper.cxx @@ -54,11 +54,10 @@ AccessibleTextHelper::~AccessibleTextHelper() void AccessibleTextHelper::initialize( const OUString& aCID, const Reference< XAccessible >& xEventSource, - const Reference< awt::XWindow >& xWindow ) + vcl::Window* pWindow) { OSL_ENSURE( !aCID.isEmpty(), "Empty CID" ); OSL_ENSURE( xEventSource.is(), "Empty Event Source" ); - OSL_ENSURE( xWindow.is(), "Empty Window" ); if( !xEventSource.is() || aCID.isEmpty() ) return; @@ -66,7 +65,6 @@ void AccessibleTextHelper::initialize( const OUString& aCID, m_oTextHelper.reset(); - VclPtr<vcl::Window> pWindow( VCLUnoHelper::GetWindow( xWindow )); if( pWindow ) { SdrView * pView = m_pDrawViewWrapper; diff --git a/chart2/source/controller/inc/AccessibleBase.hxx b/chart2/source/controller/inc/AccessibleBase.hxx index 3191fa0f252f..2b0560b6d0b5 100644 --- a/chart2/source/controller/inc/AccessibleBase.hxx +++ b/chart2/source/controller/inc/AccessibleBase.hxx @@ -30,6 +30,7 @@ #include <cppuhelper/compbase.hxx> #include <tools/color.hxx> #include <unotools/weakref.hxx> +#include <vcl/window.hxx> #include <map> #include <vector> @@ -62,7 +63,7 @@ struct AccessibleElementInfo unotools::WeakReference< ::chart::ChartModel > m_xChartDocument; unotools::WeakReference< ::chart::ChartController > m_xChartController; unotools::WeakReference< ::chart::ChartView > m_xView; - css::uno::WeakReference< css::awt::XWindow > m_xWindow; + VclPtr<vcl::Window> m_pWindow; std::shared_ptr< ObjectHierarchy > m_spObjectHierarchy; diff --git a/chart2/source/controller/inc/AccessibleChartView.hxx b/chart2/source/controller/inc/AccessibleChartView.hxx index f8fb6d302e9c..6cea437d9ccf 100644 --- a/chart2/source/controller/inc/AccessibleChartView.hxx +++ b/chart2/source/controller/inc/AccessibleChartView.hxx @@ -19,6 +19,7 @@ #pragma once #include "AccessibleBase.hxx" +#include "ChartWindow.hxx" #include <cppuhelper/implbase.hxx> #include <cppuhelper/weakref.hxx> #include <com/sun/star/lang/XInitialization.hpp> @@ -27,7 +28,6 @@ #include <memory> namespace com::sun::star::accessibility { class XAccessible; } -namespace com::sun::star::awt { class XWindow; } namespace accessibility { @@ -55,20 +55,19 @@ public: AccessibleChartView() = delete; - // ____ WeakComponentHelper (called from XComponent::dispose()) ____ - using AccessibleBase::disposing; + virtual void SAL_CALL disposing() override; // 0: view::XSelectionSupplier offers notifications for selection changes and access to the selection itself // 1: frame::XModel representing the chart model - offers access to object data // 2: lang::XInterface representing the normal chart view - offers access to some extra object data // 3: accessibility::XAccessible representing the parent accessible - // 4: awt::XWindow representing the view's window (is a vcl Window) + // 4: ChartWindow representing the view's window // all arguments are only valid until next initialization - don't keep them longer void initialize( ChartController& rChartController, const rtl::Reference<::chart::ChartModel>& xChartModel, const rtl::Reference<::chart::ChartView>& xChartView, const css::uno::Reference< css::accessibility::XAccessible >& xParent, - const css::uno::Reference<css::awt::XWindow>& xViewWindow ); + ChartWindow* pNewChartWindow); // used to disconnect from view void initialize(); @@ -106,7 +105,7 @@ private: // members unotools::WeakReference< ::chart::ChartController > m_xChartController; unotools::WeakReference< ::chart::ChartModel > m_xChartModel; unotools::WeakReference< ChartView > m_xChartView; - css::uno::WeakReference< css::awt::XWindow > m_xWindow; + VclPtr<ChartWindow> m_pChartWindow; css::uno::WeakReference< css::accessibility::XAccessible > m_xParent; std::shared_ptr< ObjectHierarchy > m_spObjectHierarchy; diff --git a/chart2/source/controller/inc/AccessibleTextHelper.hxx b/chart2/source/controller/inc/AccessibleTextHelper.hxx index 85fcb83dc3e4..f1d241391e3f 100644 --- a/chart2/source/controller/inc/AccessibleTextHelper.hxx +++ b/chart2/source/controller/inc/AccessibleTextHelper.hxx @@ -20,6 +20,7 @@ #include <comphelper/compbase.hxx> #include <svx/AccessibleTextHelper.hxx> +#include <vcl/window.hxx> #include <com/sun/star/accessibility/XAccessibleContext.hpp> #include <com/sun/star/awt/XWindow.hpp> @@ -52,12 +53,12 @@ public: mandatory parameter 1: type XAccessible. Is used as EventSource for the ::accessibility::AccessibleTextHelper (svx) - mandatory parameter 2: type awt::XWindow. The Window that shows the + mandatory parameter 2: type vcl::Window. The Window that shows the text currently. */ void initialize(const OUString& aCID, const css::uno::Reference< css::accessibility::XAccessible >& xEventSource, - const css::uno::Reference< css::awt::XWindow >& xWindow ); + vcl::Window* pWindow); // ____ XAccessibleContext ____ virtual sal_Int64 SAL_CALL getAccessibleChildCount() override; diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index 6006704492cd..9781840dcec1 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -1555,15 +1555,15 @@ void ChartController::impl_initializeAccessible() #if !ENABLE_WASM_STRIP_ACCESSIBILITY void ChartController::impl_initializeAccessible( AccessibleChartView& rAccChartView ) { + SolarMutexGuard aGuard; + uno::Reference< XAccessible > xParent; - { - SolarMutexGuard aGuard; - auto pChartWindow(GetChartWindow()); - if( pChartWindow ) - xParent.set(pChartWindow->GetAccessibleParent()); - } - rAccChartView.initialize(*this, getChartModel(), m_xChartView, xParent, m_xViewWindow); + ChartWindow* pChartWindow = GetChartWindow(); + if( pChartWindow ) + xParent.set(pChartWindow->GetAccessibleParent()); + + rAccChartView.initialize(*this, getChartModel(), m_xChartView, xParent, pChartWindow); } #else void ChartController::impl_initializeAccessible( AccessibleChartView& /* rAccChartView */) {} commit 55010423927385f7b2ff97e95799a9e03036575f Author: Michael Weghorn <[email protected]> AuthorDate: Mon Mar 31 06:28:14 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Apr 1 11:18:34 2025 +0200 chart a11y: Use nullptr directly This makes more obvious that this is null. In particular calling VCLUnoHelper::GetWindow with a Reference that is known to be empty/null doesn't make much sense. This has become more obvious with previous commit Change-Id: I91d4e9cc40473aa204ec7bcada954cf0f765e6ea Author: Michael Weghorn <[email protected]> Date: Mon Mar 31 06:14:27 2025 +0200 chart a11y: Make clearing weak refs more obvious Change-Id: Ia544001d609ede8f44003ffd4befc3cddccf045f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183519 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/chart2/source/controller/accessibility/AccessibleChartView.cxx b/chart2/source/controller/accessibility/AccessibleChartView.cxx index a3521427b45d..0a4e02e64237 100644 --- a/chart2/source/controller/accessibility/AccessibleChartView.cxx +++ b/chart2/source/controller/accessibility/AccessibleChartView.cxx @@ -356,12 +356,11 @@ void AccessibleChartView::initialize() aAccInfo.m_xChartDocument = m_xChartModel; aAccInfo.m_xChartController = m_xChartController; aAccInfo.m_xView = m_xChartView; - aAccInfo.m_xWindow = m_xWindow; + aAccInfo.m_xWindow = css::uno::WeakReference<css::awt::XWindow>(nullptr); aAccInfo.m_pParent = nullptr; aAccInfo.m_spObjectHierarchy = m_spObjectHierarchy; aAccInfo.m_pSdrView = m_pSdrView; - VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( m_xWindow ); - m_pViewForwarder.reset( new AccessibleViewForwarder( this, pWindow ) ); + m_pViewForwarder.reset(new AccessibleViewForwarder(this, nullptr)); aAccInfo.m_pViewForwarder = m_pViewForwarder.get(); // broadcasts an INVALIDATE_ALL_CHILDREN event globally SetInfo( aAccInfo ); commit a179c0a6c1c9eec319062c21a53f976282083235 Author: Michael Weghorn <[email protected]> AuthorDate: Mon Mar 31 06:14:27 2025 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Tue Apr 1 11:18:28 2025 +0200 chart a11y: Make clearing weak refs more obvious Drop the local vars that are first assigned the current value of the members, but then cleared, and then assigned to the members. Instead, clear the members directly to make more obvious what's happening. Change-Id: I91d4e9cc40473aa204ec7bcada954cf0f765e6ea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183518 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/chart2/source/controller/accessibility/AccessibleChartView.cxx b/chart2/source/controller/accessibility/AccessibleChartView.cxx index a754b9babb72..a3521427b45d 100644 --- a/chart2/source/controller/accessibility/AccessibleChartView.cxx +++ b/chart2/source/controller/accessibility/AccessibleChartView.cxx @@ -293,15 +293,11 @@ void AccessibleChartView::initialize() rtl::Reference< ::chart::ChartController > xChartController; rtl::Reference<::chart::ChartModel> xChartModel; rtl::Reference<::chart::ChartView> xChartView; - Reference< XAccessible > xParent; - Reference< awt::XWindow > xWindow; { MutexGuard aGuard( m_aMutex); xChartController = m_xChartController; xChartModel = m_xChartModel; xChartView = m_xChartView; - xParent.set( m_xParent ); - xWindow.set( m_xWindow ); } if( !xChartController.is() || !xChartModel.is() || !xChartView.is() ) @@ -328,16 +324,13 @@ void AccessibleChartView::initialize() xChartController = nullptr; } - xParent.clear(); - xWindow.clear(); - { MutexGuard aGuard( m_aMutex); m_xChartController = xChartController.get(); m_xChartModel = xChartModel.get(); m_xChartView = xChartView.get(); - m_xParent = WeakReference< XAccessible >(xParent); - m_xWindow = WeakReference< awt::XWindow >(xWindow); + m_xParent.clear(); + m_xWindow.clear(); } if( bOldInvalid )
