diff options
author | Noel Grandin <noel@peralex.com> | 2015-09-18 10:46:37 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-09-20 06:36:50 +0000 |
commit | e3c3b7fde3c017bd7d25f04fabf9b4528e37fb49 (patch) | |
tree | e25f75a698779a719b7e3cedb241dc272811499d | |
parent | 81e1e318bb47d4dc2f479ac1809d355c117f8ce8 (diff) |
convert Link<> to typed
Change-Id: I86bf78c69251b5cd4d18edf3542e70eb2e8f32e1
Reviewed-on: https://gerrit.libreoffice.org/18699
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r-- | include/vcl/menu.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/vcleventlisteners.hxx | 12 | ||||
-rw-r--r-- | vcl/source/app/vclevent.cxx | 40 | ||||
-rw-r--r-- | vcl/source/window/menu.cxx | 56 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gtksalmenu.cxx | 9 |
5 files changed, 42 insertions, 78 deletions
diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx index 456608261de6..160ef8bc34f9 100644 --- a/include/vcl/menu.hxx +++ b/include/vcl/menu.hxx @@ -404,8 +404,7 @@ public: namespace vcl { namespace MenuInvalidator { -VCL_DLLPUBLIC void AddMenuInvalidateListener(const Link<>&); -VCL_DLLPUBLIC void CallMenuInvalidateListeners(VclSimpleEvent* pEvent); +VCL_DLLPUBLIC void AddMenuInvalidateListener(const Link<LinkParamNone*,void>&); VCL_DLLPUBLIC void Invalidated(); }} diff --git a/vcl/inc/vcleventlisteners.hxx b/vcl/inc/vcleventlisteners.hxx index 8e3b026ca953..5be40e8634d2 100644 --- a/vcl/inc/vcleventlisteners.hxx +++ b/vcl/inc/vcleventlisteners.hxx @@ -41,18 +41,6 @@ private: std::vector<Link<>> m_aListeners; }; -class VCL_DLLPUBLIC VclEventListeners2 : public vcl::DeletionNotifier -{ - std::vector<Link<>> m_aListeners; -public: - VclEventListeners2(); - ~VclEventListeners2(); - - void addListener( const Link<>& ); - void removeListener( const Link<>& ); - void callListeners( VclSimpleEvent* ); -}; - #endif // INCLUDED_VCL_INC_VCLEVENTLISTENERS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/app/vclevent.cxx b/vcl/source/app/vclevent.cxx index 7cb291d95eb5..6cc4523ba983 100644 --- a/vcl/source/app/vclevent.cxx +++ b/vcl/source/app/vclevent.cxx @@ -87,46 +87,6 @@ void VclEventListeners::removeListener( const Link<>& rListener ) m_aListeners.erase( std::remove(m_aListeners.begin(), m_aListeners.end(), rListener ), m_aListeners.end() ); } -VclEventListeners2::VclEventListeners2() -{ -} - -VclEventListeners2::~VclEventListeners2() -{ -} - -void VclEventListeners2::addListener( const Link<>& rListener ) -{ - // ensure uniqueness - if (std::find(m_aListeners.begin(), m_aListeners.end(), rListener) == m_aListeners.end()) - m_aListeners.push_back( rListener ); -} - -void VclEventListeners2::removeListener( const Link<>& rListener ) -{ - m_aListeners.erase( std::remove(m_aListeners.begin(), m_aListeners.end(), rListener ), m_aListeners.end() ); -} - -void VclEventListeners2::callListeners( VclSimpleEvent* pEvent ) -{ - vcl::DeletionListener aDel( this ); - - // Copy the list, because this can be destroyed when calling a Link... - std::vector<Link<>> aCopy( m_aListeners ); - std::vector<Link<>>::iterator aIter( aCopy.begin() ); - std::vector<Link<>>::const_iterator aEnd( aCopy.end() ); - - while ( aIter != aEnd && ! aDel.isDeleted() ) - { - Link<> &rLink = *aIter; - // check this hasn't been removed in some re-enterancy scenario fdo#47368 - if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() ) - rLink.Call( pEvent ); - ++aIter; - } -} - - VclWindowEvent::VclWindowEvent( vcl::Window* pWin, sal_uLong n, void* pDat ) : VclSimpleEvent(n) { pWindow = pWin; pData = pDat; diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index e5acc2eca589..23f857aa3273 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -3239,25 +3239,43 @@ ImplMenuDelData::~ImplMenuDelData() } namespace vcl { namespace MenuInvalidator { - static VclEventListeners2* pMenuInvalidateListeners = NULL; - void AddMenuInvalidateListener(const Link<>& rLink) - { - if(!pMenuInvalidateListeners) - pMenuInvalidateListeners = new VclEventListeners2(); - pMenuInvalidateListeners->addListener(rLink); - } - void CallMenuInvalidateListeners(VclSimpleEvent* pEvent) + +struct MenuInvalidateListeners : public vcl::DeletionNotifier +{ + std::vector<Link<LinkParamNone*,void>> m_aListeners; +}; + +static MenuInvalidateListeners* pMenuInvalidateListeners = NULL; + +void AddMenuInvalidateListener(const Link<LinkParamNone*,void>& rLink) +{ + if(!pMenuInvalidateListeners) + pMenuInvalidateListeners = new MenuInvalidateListeners(); + // ensure uniqueness + auto& rListeners = pMenuInvalidateListeners->m_aListeners; + if (std::find(rListeners.begin(), rListeners.end(), rLink) == rListeners.end()) + rListeners.push_back( rLink ); +} + +void Invalidated() +{ + if(!pMenuInvalidateListeners) + return; + + vcl::DeletionListener aDel( pMenuInvalidateListeners ); + + auto& rYieldListeners = pMenuInvalidateListeners->m_aListeners; + // Copy the list, because this can be destroyed when calling a Link... + std::vector<Link<LinkParamNone*,void>> aCopy( rYieldListeners ); + for( Link<LinkParamNone*,void>& rLink : aCopy ) { - if(pMenuInvalidateListeners) - pMenuInvalidateListeners->callListeners(pEvent); + if (aDel.isDeleted()) break; + // check this hasn't been removed in some re-enterancy scenario fdo#47368 + if( std::find(rYieldListeners.begin(), rYieldListeners.end(), rLink) != rYieldListeners.end() ) + rLink.Call( nullptr ); } - void Invalidated() - { - if(pMenuInvalidateListeners) - { - VclSimpleEvent aEvent(0); - pMenuInvalidateListeners->callListeners(&aEvent); - } - }; -} } +}; + +} } // namespace vcl::MenuInvalidator + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx index ba2c894a86db..bb53b14ff341 100644 --- a/vcl/unx/gtk/window/gtksalmenu.cxx +++ b/vcl/unx/gtk/window/gtksalmenu.cxx @@ -392,20 +392,19 @@ static gboolean RefreshMenusUnity(gpointer) return FALSE; } -static long RefreshMenusUnity(void*, void*) +static void RefreshMenusUnity(void*, LinkParamNone*) { if(!bInvalidMenus) { g_timeout_add(10, &RefreshMenusUnity, NULL); bInvalidMenus = true; } - return 0; } -static Link<>* getRefreshLinkInstance() +static Link<LinkParamNone*,void>* getRefreshLinkInstance() { - static Link<>* pLink = NULL; + static Link<LinkParamNone*,void>* pLink = NULL; if(!pLink) { - pLink = new Link<>(NULL, &RefreshMenusUnity); + pLink = new Link<LinkParamNone*,void>(NULL, &RefreshMenusUnity); } return pLink; } |