chart2/source/controller/accessibility/AccessibleBase.cxx | 5 chart2/source/controller/accessibility/AccessibleChartElement.cxx | 9 chart2/source/controller/accessibility/AccessibleChartView.cxx | 206 ++++++---- chart2/source/controller/inc/AccessibleBase.hxx | 3 chart2/source/controller/inc/AccessibleChartView.hxx | 17 chart2/source/controller/inc/ChartController.hxx | 4 chart2/source/controller/main/ChartController.cxx | 29 - 7 files changed, 166 insertions(+), 107 deletions(-)
New commits: commit bdf2d664784b3ebe3e7078b9ec82a02d09d9ded8 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sat Sep 2 10:44:51 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Sep 2 15:01:44 2023 +0200 use more concrete type in AccessibleChartView Change-Id: I1ec6c7bdd0f7ab487ba1ade89cd545f5bc97f540 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156466 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/chart2/source/controller/accessibility/AccessibleBase.cxx b/chart2/source/controller/accessibility/AccessibleBase.cxx index 29a3eb23b426..905c7f89696e 100644 --- a/chart2/source/controller/accessibility/AccessibleBase.cxx +++ b/chart2/source/controller/accessibility/AccessibleBase.cxx @@ -22,6 +22,7 @@ #include <ObjectHierarchy.hxx> #include <ObjectIdentifier.hxx> #include <ChartView.hxx> +#include <ChartController.hxx> #include <chartview/ExplicitValueProvider.hxx> #include <com/sun/star/accessibility/AccessibleEventId.hpp> @@ -535,7 +536,7 @@ sal_Int64 SAL_CALL AccessibleBase::getAccessibleStateSet() { if( ! m_bStateSetInitialized ) { - Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier ); + rtl::Reference< ::chart::ChartController > xSelSupp( GetInfo().m_xChartController ); if ( xSelSupp.is() ) { ObjectIdentifier aOID( xSelSupp->getSelection() ); @@ -679,7 +680,7 @@ void SAL_CALL AccessibleBase::grabFocus() { CheckDisposeState(); - Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier ); + rtl::Reference< ::chart::ChartController > xSelSupp( GetInfo().m_xChartController ); if ( xSelSupp.is() ) { xSelSupp->select( GetId().getAny() ); diff --git a/chart2/source/controller/accessibility/AccessibleChartElement.cxx b/chart2/source/controller/accessibility/AccessibleChartElement.cxx index 8b37b002d76d..cca038b5be94 100644 --- a/chart2/source/controller/accessibility/AccessibleChartElement.cxx +++ b/chart2/source/controller/accessibility/AccessibleChartElement.cxx @@ -20,6 +20,7 @@ #include "AccessibleChartElement.hxx" #include <CharacterProperties.hxx> #include <ChartModel.hxx> +#include <ChartController.hxx> #include <ObjectIdentifier.hxx> #include <ObjectNameProvider.hxx> #include <servicenames.hxx> @@ -85,13 +86,11 @@ void AccessibleChartElement::InitTextEdit() if( ! m_xTextHelper.is()) { // get hard reference - Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier ); - // get factory from selection supplier (controller) - Reference< lang::XMultiServiceFactory > xFact( xSelSupp, uno::UNO_QUERY ); - if( xFact.is()) + rtl::Reference< ::chart::ChartController > xSelSupp( GetInfo().m_xChartController ); + if( xSelSupp.is()) { m_xTextHelper.set( - xFact->createInstance( CHART_ACCESSIBLE_TEXT_SERVICE_NAME ), uno::UNO_QUERY ); + xSelSupp->createInstance( CHART_ACCESSIBLE_TEXT_SERVICE_NAME ), uno::UNO_QUERY ); } } diff --git a/chart2/source/controller/accessibility/AccessibleChartView.cxx b/chart2/source/controller/accessibility/AccessibleChartView.cxx index 1f23976d44e5..8f4103ee6060 100644 --- a/chart2/source/controller/accessibility/AccessibleChartView.cxx +++ b/chart2/source/controller/accessibility/AccessibleChartView.cxx @@ -26,6 +26,7 @@ #include "AccessibleViewForwarder.hxx" #include <ChartModel.hxx> #include <ChartView.hxx> +#include <ChartController.hxx> #include <com/sun/star/accessibility/AccessibleStateType.hpp> #include <com/sun/star/accessibility/AccessibleRole.hpp> @@ -158,9 +159,11 @@ awt::Point SAL_CALL AccessibleChartView::getLocationOnScreen() return aResult; } -// lang::XInitialization - -void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments ) +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 ) { //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 @@ -171,109 +174,71 @@ void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments bool bOldInvalid = false; bool bNewInvalid = false; - Reference< view::XSelectionSupplier > xSelectionSupplier; + 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); - xSelectionSupplier.set( m_xSelectionSupplier ); + xChartController = m_xChartController; xChartModel = m_xChartModel; xChartView = m_xChartView; xParent.set( m_xParent ); xWindow.set( m_xWindow ); } - if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() ) + if( !xChartController.is() || !xChartModel.is() || !xChartView.is() ) { bOldInvalid = true; } - if( rArguments.getLength() > 1 ) - { - Reference< frame::XModel > xNewChartModel; - rArguments[1] >>= xNewChartModel; - assert(!xNewChartModel || dynamic_cast<::chart::ChartModel*>(xNewChartModel.get())); - ::chart::ChartModel* pNewChartModel = dynamic_cast<::chart::ChartModel*>(xNewChartModel.get()); - if( pNewChartModel != xChartModel.get() ) - { - xChartModel = pNewChartModel; - bChanged = true; - } - } - else if( xChartModel.is() ) + if( xNewChartModel.get() != xChartModel.get() ) { + xChartModel = xNewChartModel; bChanged = true; - xChartModel = nullptr; } - if( rArguments.getLength() > 2 ) - { - Reference< uno::XInterface > xTmp; - rArguments[2] >>= xTmp; - rtl::Reference<::chart::ChartView> xNewChartView = dynamic_cast<::chart::ChartView*>(xTmp.get()); - assert(bool(xTmp)==bool(xNewChartView) && "we only support ChartView"); - if( xNewChartView != xChartView ) - { - xChartView = xNewChartView; - bChanged = true; - } - } - else if( xChartView.is() ) + if( xNewChartView != xChartView ) { + xChartView = xNewChartView; bChanged = true; - xChartView = nullptr; } - if( rArguments.getLength() > 3 ) + if( xNewParent != xParent ) { - Reference< XAccessible > xNewParent; - rArguments[3] >>= xNewParent; - if( xNewParent != xParent ) - { - xParent = xNewParent; - bChanged = true; - } + xParent = xNewParent; + bChanged = true; } - if( rArguments.getLength() > 4 ) + if( xNewWindow != xWindow ) { - Reference< awt::XWindow > xNewWindow; - rArguments[4] >>= xNewWindow; - if( xNewWindow != xWindow ) - { - xWindow.set( xNewWindow ); - bChanged = true; - } + xWindow.set( xNewWindow ); + bChanged = true; } - if( rArguments.hasElements() && xChartModel.is() && xChartView.is() ) + if( xChartModel.is() && xChartView.is() ) { - Reference< view::XSelectionSupplier > xNewSelectionSupplier; - rArguments[0] >>= xNewSelectionSupplier; - if(xSelectionSupplier!=xNewSelectionSupplier) + if(xChartController != &rNewChartController) { bChanged = true; - if(xSelectionSupplier.is()) - xSelectionSupplier->removeSelectionChangeListener(this); - if(xNewSelectionSupplier.is()) - xNewSelectionSupplier->addSelectionChangeListener(this); - xSelectionSupplier = xNewSelectionSupplier; + xChartController->removeSelectionChangeListener(this); + rNewChartController.addSelectionChangeListener(this); + xChartController = &rNewChartController; } } - else if( xSelectionSupplier.is() ) + else if( xChartController.is() ) { bChanged = true; - xSelectionSupplier->removeSelectionChangeListener(this); - xSelectionSupplier = nullptr; + xChartController->removeSelectionChangeListener(this); + xChartController = nullptr; } - if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() ) + if( !xChartController.is() || !xChartModel.is() || !xChartView.is() ) { - if(xSelectionSupplier.is()) - xSelectionSupplier->removeSelectionChangeListener(this); - xSelectionSupplier = nullptr; + if(xChartController.is()) + xChartController->removeSelectionChangeListener(this); + xChartController = nullptr; xChartModel.clear(); xChartView.clear(); xParent.clear(); @@ -284,14 +249,109 @@ void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments { MutexGuard aGuard( m_aMutex); - m_xSelectionSupplier = WeakReference< view::XSelectionSupplier >(xSelectionSupplier); + m_xChartController = xChartController.get(); + m_xChartModel = xChartModel.get(); + m_xChartView = xChartView.get(); + m_xParent = xParent; + m_xWindow = xWindow; + } + + if( bOldInvalid && bNewInvalid ) + bChanged = false; + + if( !bChanged ) + return; + + { + //before notification we prepare for creation of new context + //the old context will be deleted after notification than + MutexGuard aGuard( m_aMutex); + if( xChartModel.is()) + m_spObjectHierarchy = + std::make_shared<ObjectHierarchy>( xChartModel, m_xChartView.get().get() ); + else + m_spObjectHierarchy.reset(); + } + + { + AccessibleElementInfo aAccInfo; + aAccInfo.m_aOID = ObjectIdentifier("ROOT"); + aAccInfo.m_xChartDocument = m_xChartModel; + aAccInfo.m_xChartController = m_xChartController; + aAccInfo.m_xView = m_xChartView; + aAccInfo.m_xWindow = m_xWindow; + 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 ) ); + aAccInfo.m_pViewForwarder = m_pViewForwarder.get(); + // broadcasts an INVALIDATE_ALL_CHILDREN event globally + SetInfo( aAccInfo ); + } +} + +void AccessibleChartView::initialize() +{ + //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 + + //all arguments are only valid until next initialization + bool bChanged = false; + bool bOldInvalid = false; + + 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() ) + { + bOldInvalid = true; + } + + if( xChartModel.is() ) + { + bChanged = true; + xChartModel = nullptr; + } + + if( xChartView.is() ) + { + bChanged = true; + xChartView = nullptr; + } + + if( xChartController.is() ) + { + bChanged = true; + xChartController->removeSelectionChangeListener(this); + 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); } - if( bOldInvalid && bNewInvalid ) + if( bOldInvalid ) bChanged = false; if( !bChanged ) @@ -312,7 +372,7 @@ void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments AccessibleElementInfo aAccInfo; aAccInfo.m_aOID = ObjectIdentifier("ROOT"); aAccInfo.m_xChartDocument = m_xChartModel; - aAccInfo.m_xSelectionSupplier = m_xSelectionSupplier; + aAccInfo.m_xChartController = m_xChartController; aAccInfo.m_xView = m_xChartView; aAccInfo.m_xWindow = m_xWindow; aAccInfo.m_pParent = nullptr; @@ -330,16 +390,16 @@ void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments void SAL_CALL AccessibleChartView::selectionChanged( const lang::EventObject& /*rEvent*/ ) { - Reference< view::XSelectionSupplier > xSelectionSupplier; + rtl::Reference< ::chart::ChartController > xChartController; { MutexGuard aGuard( m_aMutex); - xSelectionSupplier.set(m_xSelectionSupplier); + xChartController = m_xChartController.get(); } - if( !xSelectionSupplier.is() ) + if( !xChartController.is() ) return; - ObjectIdentifier aSelectedOID( xSelectionSupplier->getSelection() ); + ObjectIdentifier aSelectedOID( xChartController->getSelection() ); if ( m_aCurrentSelectionOID.isValid() ) { NotifyEvent( EventType::LOST_SELECTION, m_aCurrentSelectionOID ); diff --git a/chart2/source/controller/inc/AccessibleBase.hxx b/chart2/source/controller/inc/AccessibleBase.hxx index 6c1bc93b326f..a6076a0cc14c 100644 --- a/chart2/source/controller/inc/AccessibleBase.hxx +++ b/chart2/source/controller/inc/AccessibleBase.hxx @@ -55,6 +55,7 @@ namespace chart class AccessibleBase; class ChartView; class ObjectHierarchy; +class ChartController; typedef ObjectIdentifier AccessibleUniqueId; @@ -63,7 +64,7 @@ struct AccessibleElementInfo AccessibleUniqueId m_aOID; unotools::WeakReference< ::chart::ChartModel > m_xChartDocument; - css::uno::WeakReference< css::view::XSelectionSupplier > m_xSelectionSupplier; + unotools::WeakReference< ::chart::ChartController > m_xChartController; unotools::WeakReference< ::chart::ChartView > m_xView; css::uno::WeakReference< css::awt::XWindow > m_xWindow; diff --git a/chart2/source/controller/inc/AccessibleChartView.hxx b/chart2/source/controller/inc/AccessibleChartView.hxx index c66578c0c09e..793cdd69ab77 100644 --- a/chart2/source/controller/inc/AccessibleChartView.hxx +++ b/chart2/source/controller/inc/AccessibleChartView.hxx @@ -44,7 +44,6 @@ namespace impl { typedef ::cppu::ImplInheritanceHelper< ::chart::AccessibleBase, - css::lang::XInitialization, css::view::XSelectionChangeListener > AccessibleChartView_Base; } @@ -53,7 +52,7 @@ class AccessibleChartView final : public impl::AccessibleChartView_Base { public: - AccessibleChartView(SdrView* pView ); + AccessibleChartView( SdrView* pView ); virtual ~AccessibleChartView() override; AccessibleChartView() = delete; @@ -61,15 +60,19 @@ public: // ____ WeakComponentHelper (called from XComponent::dispose()) ____ using AccessibleBase::disposing; - // ____ lang::XInitialization ____ // 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) // all arguments are only valid until next initialization - don't keep them longer - virtual void SAL_CALL initialize( - const css::uno::Sequence< css::uno::Any >& aArguments ) override; + 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 ); + // used to disconnect from view + void initialize(); // ____ view::XSelectionChangeListener ____ virtual void SAL_CALL selectionChanged( const css::lang::EventObject& aEvent ) override; @@ -102,8 +105,8 @@ private: // methods css::awt::Rectangle GetWindowPosSize() const; private: // members - css::uno::WeakReference< css::view::XSelectionSupplier > m_xSelectionSupplier; - unotools::WeakReference<::chart::ChartModel> m_xChartModel; + 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; css::uno::WeakReference< css::accessibility::XAccessible > m_xParent; diff --git a/chart2/source/controller/inc/ChartController.hxx b/chart2/source/controller/inc/ChartController.hxx index 63fb4d4fc302..0a98b8df0364 100644 --- a/chart2/source/controller/inc/ChartController.hxx +++ b/chart2/source/controller/inc/ChartController.hxx @@ -61,7 +61,6 @@ namespace com::sun::star::uno { class XComponentContext; } namespace com::sun::star::util { class XCloseable; } namespace com::sun::star::view { class XSelectionSupplier; } - class SdrModel; namespace svt @@ -90,6 +89,7 @@ class DrawViewWrapper; class ReferenceSizeProvider; class ViewElementListProvider; class Diagram; +class AccessibleChartView; enum ChartDrawMode { CHARTDRAW_INSERT, CHARTDRAW_SELECT }; @@ -529,7 +529,7 @@ private: void impl_notifySelectionChangeListeners(); void impl_invalidateAccessible(); void impl_initializeAccessible(); - void impl_initializeAccessible( const css::uno::Reference< css::lang::XInitialization >& xInit ); + void impl_initializeAccessible( AccessibleChartView& xInit ); //sets the model member to null if it equals the parameter //returns true if successful diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index 1c85ab369269..d33fceff86be 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -1571,8 +1571,8 @@ void ChartController::SetAndApplySelection(const Reference<drawing::XShape>& rxS uno::Reference< XAccessible > ChartController::CreateAccessible() { #if !ENABLE_WASM_STRIP_ACCESSIBILITY - uno::Reference< XAccessible > xResult = new AccessibleChartView( GetDrawViewWrapper() ); - impl_initializeAccessible( uno::Reference< lang::XInitialization >( xResult, uno::UNO_QUERY ) ); + rtl::Reference< AccessibleChartView > xResult = new AccessibleChartView( GetDrawViewWrapper() ); + impl_initializeAccessible( *xResult ); return xResult; #else return uno::Reference< XAccessible >(); @@ -1585,11 +1585,11 @@ void ChartController::impl_invalidateAccessible() auto pChartWindow(GetChartWindow()); if( pChartWindow ) { - Reference< lang::XInitialization > xInit( pChartWindow->GetAccessible(false), uno::UNO_QUERY ); + Reference< XInterface > xInit( pChartWindow->GetAccessible(false) ); if(xInit.is()) { - uno::Sequence< uno::Any > aArguments(3);//empty arguments -> invalid accessible - xInit->initialize(aArguments); + //empty arguments -> invalid accessible + dynamic_cast<AccessibleChartView&>(*xInit).initialize(); } } } @@ -1597,14 +1597,14 @@ void ChartController::impl_initializeAccessible() { SolarMutexGuard aGuard; auto pChartWindow(GetChartWindow()); - if( pChartWindow ) - this->impl_initializeAccessible( Reference< lang::XInitialization >( pChartWindow->GetAccessible(false), uno::UNO_QUERY ) ); + if( !pChartWindow ) + return; + Reference< XInterface > xInit( pChartWindow->GetAccessible(false) ); + if(xInit.is()) + impl_initializeAccessible( dynamic_cast<AccessibleChartView&>(*xInit) ); } -void ChartController::impl_initializeAccessible( const uno::Reference< lang::XInitialization >& xInit ) +void ChartController::impl_initializeAccessible( AccessibleChartView& rAccChartView ) { - if(!xInit.is()) - return; - uno::Reference< XAccessible > xParent; { SolarMutexGuard aGuard; @@ -1616,13 +1616,8 @@ void ChartController::impl_initializeAccessible( const uno::Reference< lang::XIn xParent.set( pParentWin->GetAccessible()); } } - uno::Sequence< uno::Any > aArguments{ uno::Any(uno::Reference<view::XSelectionSupplier>(this)), - uno::Any(getModel()), - uno::Any(uno::Reference<XInterface>(static_cast<cppu::OWeakObject*>(m_xChartView.get()))), - uno::Any(xParent), - uno::Any(m_xViewWindow) }; - xInit->initialize(aArguments); + rAccChartView.initialize(*this, getChartModel(), m_xChartView, xParent, m_xViewWindow); } const o3tl::sorted_vector< OUString >& ChartController::impl_getAvailableCommands()