From c70fd83a916770d068e2278c0e6f105826178858 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 20 Nov 2013 20:27:11 +0100 Subject: winaccessibility: clean up global TopLevelWindowListener Apparently the life-cycle of this global variable is tied to the MSAAService anyway, so just make it a member of that. Also it appears that the FreeTopListener function would call release() but at the place where the global variable is assigned acquire() was missing. Using a rtl::Reference should fix this up too. Change-Id: I6dd305dfd990d7fd4c54b16d971700b88470dc43 --- winaccessibility/inc/g_msacc.hxx | 4 ---- .../source/service/AccTopWindowListener.cxx | 23 ------------------- .../source/service/msaaservice_impl.cxx | 26 ++++++++++++++-------- 3 files changed, 17 insertions(+), 36 deletions(-) (limited to 'winaccessibility') diff --git a/winaccessibility/inc/g_msacc.hxx b/winaccessibility/inc/g_msacc.hxx index 9f851bf42622..b9670cfa50bb 100644 --- a/winaccessibility/inc/g_msacc.hxx +++ b/winaccessibility/inc/g_msacc.hxx @@ -20,12 +20,8 @@ #ifndef __G_MSACC_HXX #define __G_MSACC_HXX -extern void FreeTopWindowListener(); -extern void handleWindowOpened_impl(sal_Int64 pAcc); extern sal_Int64 GetMSComPtr(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam); -extern AccTopWindowListener* g_pTop; - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/winaccessibility/source/service/AccTopWindowListener.cxx b/winaccessibility/source/service/AccTopWindowListener.cxx index 7900bf6c36f7..a463ca4ec5a5 100644 --- a/winaccessibility/source/service/AccTopWindowListener.cxx +++ b/winaccessibility/source/service/AccTopWindowListener.cxx @@ -44,29 +44,6 @@ using namespace com::sun::star::awt; using namespace rtl; using namespace cppu; -AccTopWindowListener* g_pTop = NULL; - -//when proccess exit, call FreeTopWindowListener() in svmain -void FreeTopWindowListener() -{ - if( g_pTop ) - { - g_pTop->release(); - g_pTop = NULL; - } -} - -/** - * As a global method to invoke the handleWindowOpened() method - */ -void handleWindowOpened_impl(sal_Int64 pAcc) -{ - if( g_pTop && pAcc != 0 ) - g_pTop->HandleWindowOpened( - static_cast( - reinterpret_cast(pAcc))); -} - /** * For the new opened window, generate all the UNO accessible's object, COM object and add * accessible listener to monitor all these objects. diff --git a/winaccessibility/source/service/msaaservice_impl.cxx b/winaccessibility/source/service/msaaservice_impl.cxx index b68efde7366c..ff3b017fb4cd 100644 --- a/winaccessibility/source/service/msaaservice_impl.cxx +++ b/winaccessibility/source/service/msaaservice_impl.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include #include #include @@ -35,7 +36,6 @@ #include #include -using namespace ::rtl; // for OUString using namespace ::com::sun::star; // for odk interfaces using namespace ::com::sun::star::uno; // for basic types using namespace ::com::sun::star::accessibility; @@ -64,12 +64,13 @@ class MSAAServiceImpl : public ::cppu::WeakImplHelper4< XMSAAService, lang::XServiceInfo, lang::XInitialization, lang::XComponent > { +private: + rtl::Reference m_pTopWindowListener; OUString m_arg; + public: - // focus on four interfaces, - // no need to implement XInterface, XTypeProvider, XWeak etc. MSAAServiceImpl (); - virtual ~MSAAServiceImpl( void ); + virtual ~MSAAServiceImpl(); // XInitialization will be called upon createInstanceWithArguments[AndContext]() virtual void SAL_CALL initialize( Sequence< Any > const & args ) throw (Exception); @@ -133,7 +134,13 @@ void MSAAServiceImpl::handleWindowOpened(sal_Int64 nAcc) SolarMutexGuard g; SAL_INFO( "iacc2", "Window opened " << nAcc ); - handleWindowOpened_impl( nAcc ); + + if (m_pTopWindowListener.is() && nAcc) + { + m_pTopWindowListener->HandleWindowOpened( + static_cast( + reinterpret_cast(nAcc))); + } } OUString MSAAServiceImpl::getImplementationName() throw (RuntimeException) @@ -221,7 +228,8 @@ static void AccessBridgeHandleExistingWindow(const Reference< XMSAAService > &xA assert( xAccMgr.is() ); if ( xAccessible.is() ) { - xAccMgr->handleWindowOpened( (long)xAccessible.get() ); + xAccMgr->handleWindowOpened( + reinterpret_cast(xAccessible.get())); SAL_INFO( "iacc2", "Decide whether to register existing window with IAccessible2" ); } } @@ -300,8 +308,8 @@ MSAAServiceImpl::MSAAServiceImpl() if( xToolkit.is() ) { - g_pTop = new AccTopWindowListener(); - Reference< XTopWindowListener> xRef( g_pTop ); + m_pTopWindowListener.set(new AccTopWindowListener()); + Reference const xRef(m_pTopWindowListener.get()); xToolkit->addTopWindowListener( xRef ); SAL_INFO( "iacc2", "successfully connected to the toolkit event hose" ); } @@ -323,7 +331,7 @@ void MSAAServiceImpl::dispose() // and substreams which in turn release theirs, etc. When xRootFolder is // released when this destructor completes, the folder tree should be // deleted fully (and automagically). - FreeTopWindowListener(); + m_pTopWindowListener.clear(); } } -- cgit