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 /vcl/source/window | |
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>
Diffstat (limited to 'vcl/source/window')
-rw-r--r-- | vcl/source/window/menu.cxx | 56 |
1 files changed, 37 insertions, 19 deletions
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: */ |