diff --git a/winaccessibility/inc/AccTopWindowListener.hxx b/winaccessibility/inc/AccTopWindowListener.hxx index 9d8b46f95acc..2623dd2db737 100644 --- a/winaccessibility/inc/AccTopWindowListener.hxx +++ b/winaccessibility/inc/AccTopWindowListener.hxx @@ -24,6 +24,7 @@ #include #include +#include #include "AccObjectWinManager.hxx" @@ -58,7 +59,7 @@ public: void AddAllListeners(css::accessibility::XAccessible* pAccessible, css::accessibility::XAccessible* pParentXAcc, HWND pWND); //for On-Demand load. - void HandleWindowOpened(css::accessibility::XAccessible* pAccessible); + void HandleWindowOpened(vcl::Window* pWindow); sal_Int64 GetMSComPtr(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam); }; diff --git a/winaccessibility/source/service/AccTopWindowListener.cxx b/winaccessibility/source/service/AccTopWindowListener.cxx index 1b61a6436b15..f19a16b26acc 100644 --- a/winaccessibility/source/service/AccTopWindowListener.cxx +++ b/winaccessibility/source/service/AccTopWindowListener.cxx @@ -36,40 +36,38 @@ using namespace com::sun::star::uno; /** * For the new opened window, generate all the UNO accessible's object, COM object and add * accessible listener to monitor all these objects. - * @param pAccessible the accessible of the new opened window + * @param pWindow the new opened window */ -void AccTopWindowListener::HandleWindowOpened( css::accessibility::XAccessible* pAccessible ) +void AccTopWindowListener::HandleWindowOpened(vcl::Window* pWindow) { - //get SystemData from window - VclPtr window; - if (auto pvclwindow = dynamic_cast(pAccessible)) - window = pvclwindow->GetWindow(); - else if (auto pvclxcomponent = dynamic_cast(pAccessible)) - window = pvclxcomponent->GetWindow(); - assert(window); + assert(pWindow); - const SystemEnvData* pSystemData = window->GetSystemData(); + const SystemEnvData* pSystemData = pWindow->GetSystemData(); if (!pSystemData) return; - Reference xContext = pAccessible->getAccessibleContext(); + Reference xAccessible = pWindow->GetAccessible(); + if (!xAccessible.is()) + return; + + Reference xContext = xAccessible->getAccessibleContext(); if(!xContext.is()) return; // add all listeners - m_aAccObjectManager.SaveTopWindowHandle(pSystemData->hWnd, pAccessible); + m_aAccObjectManager.SaveTopWindowHandle(pSystemData->hWnd, xAccessible.get()); - AddAllListeners(pAccessible, nullptr, pSystemData->hWnd); + AddAllListeners(xAccessible.get(), nullptr, pSystemData->hWnd); - if( window->GetStyle() & WB_MOVEABLE ) - m_aAccObjectManager.IncreaseState( pAccessible, static_cast(-1) /* U_MOVEBLE */ ); + if (pWindow->GetStyle() & WB_MOVEABLE) + m_aAccObjectManager.IncreaseState(xAccessible.get(), static_cast(-1) /* U_MOVEBLE */ ); short role = xContext->getAccessibleRole(); if (role == css::accessibility::AccessibleRole::POPUP_MENU || role == css::accessibility::AccessibleRole::MENU ) { - m_aAccObjectManager.NotifyAccEvent(pAccessible, UnoMSAAEvent::MENUPOPUPSTART); + m_aAccObjectManager.NotifyAccEvent(xAccessible.get(), UnoMSAAEvent::MENUPOPUPSTART); } if (role == css::accessibility::AccessibleRole::FRAME || @@ -77,7 +75,7 @@ void AccTopWindowListener::HandleWindowOpened( css::accessibility::XAccessible* role == css::accessibility::AccessibleRole::WINDOW || role == css::accessibility::AccessibleRole::ALERT) { - m_aAccObjectManager.NotifyAccEvent(pAccessible, UnoMSAAEvent::SHOW); + m_aAccObjectManager.NotifyAccEvent(xAccessible.get(), UnoMSAAEvent::SHOW); } } @@ -100,14 +98,15 @@ void AccTopWindowListener::windowOpened( const css::lang::EventObject& e ) if ( !e.Source.is()) return; - Reference< css::accessibility::XAccessible > xAccessible ( e.Source, UNO_QUERY ); - css::accessibility::XAccessible* pAccessible = xAccessible.get(); - if ( !pAccessible ) - return; - SolarMutexGuard g; - HandleWindowOpened( pAccessible ); + VCLXWindow* pVCLXWindow = dynamic_cast(e.Source.get()); + assert(pVCLXWindow && "Window is not a VCLXWindow"); + + vcl::Window* pWindow = pVCLXWindow->GetWindow(); + assert(pWindow); + + HandleWindowOpened(pWindow); } /** @@ -172,7 +171,13 @@ void AccTopWindowListener::windowClosed( const css::lang::EventObject& e ) if ( !e.Source.is()) return; - Reference< css::accessibility::XAccessible > xAccessible ( e.Source, UNO_QUERY ); + VCLXWindow* pVCLXWindow = dynamic_cast(e.Source.get()); + assert(pVCLXWindow && "Window is not a VCLXWindow"); + + vcl::Window* pWindow = pVCLXWindow->GetWindow(); + assert(pWindow); + + Reference xAccessible = pWindow->GetAccessible(); if (!xAccessible.is()) return; diff --git a/winaccessibility/source/service/msaaservice_impl.cxx b/winaccessibility/source/service/msaaservice_impl.cxx index 955d30560c6c..823238215a25 100644 --- a/winaccessibility/source/service/msaaservice_impl.cxx +++ b/winaccessibility/source/service/msaaservice_impl.cxx @@ -109,7 +109,7 @@ void MSAAServiceImpl::handleWindowOpened(sal_Int64 nAcc) if (m_pTopWindowListener.is() && nAcc) { m_pTopWindowListener->HandleWindowOpened( - static_cast( + static_cast( reinterpret_cast(nAcc))); } } @@ -142,19 +142,9 @@ Sequence< OUString > MSAAServiceImpl::getSupportedServiceNames() static void AccessBridgeHandleExistingWindow(const Reference< XMSAAService>& xAccMgr, vcl::Window* pWindow) { - assert(pWindow); - - // We have to rely on the fact that Window::GetAccessible()->getAccessibleContext() returns a valid XAccessibleContext - // also for other menus than menubar or toplevel popup window. Otherwise we had to traverse the hierarchy to find the - // context object to this menu floater. This makes the call to Window->IsMenuFloatingWindow() obsolete. - css::uno::Reference xAccessible = pWindow->GetAccessible(); - assert(xAccMgr.is()); - if (xAccessible.is()) - { - xAccMgr->handleWindowOpened(reinterpret_cast(xAccessible.get())); - SAL_INFO("iacc2", "Decide whether to register existing window with IAccessible2"); - } + assert(pWindow); + xAccMgr->handleWindowOpened(reinterpret_cast(pWindow)); } /*