From d72015591024509ecb3cd48d03113e0acd3d9f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sun, 11 Dec 2016 16:53:33 +0100 Subject: [PATCH] Defer wxAccessible::NotifyEvent() to idle time Change NotifyEvent() implementation so that it doesn't call ::NotifyWinEvent() immediately, but only in the next iteration of the event loop. This makes it easier to write code that uses, because it must be called after the changes it notifies about were fully made and are visible in the corresponding window's accessible interface. --- src/msw/ole/access.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/msw/ole/access.cpp b/src/msw/ole/access.cpp index 6c68fb29b7..b0b532208e 100644 --- a/src/msw/ole/access.cpp +++ b/src/msw/ole/access.cpp @@ -28,6 +28,7 @@ #include "wx/access.h" #ifndef WX_PRECOMP + #include "wx/app.h" #include "wx/msw/wrapwin.h" #include "wx/window.h" #include "wx/log.h" @@ -1823,12 +1824,36 @@ IAccessible *wxAccessible::GetIAccessibleStd() return NULL; } +namespace +{ + +struct SendNotification +{ + SendNotification(DWORD eventType_, HWND hwnd_, LONG idObject_, LONG idChild_) + : eventType(eventType_), hwnd(hwnd_), idObject(idObject_), idChild(idChild_) + {} + + void operator()(void) + { + ::NotifyWinEvent(eventType, hwnd, idObject, idChild); + } + + DWORD eventType; + HWND hwnd; + LONG idObject, idChild; +}; + +} // anonymous namespace + // Sends an event when something changes in an accessible object. void wxAccessible::NotifyEvent(int eventType, wxWindow* window, wxAccObject objectType, int objectId) { - ::NotifyWinEvent((DWORD) eventType, (HWND) window->GetHWND(), - (LONG) objectType, (LONG) objectId); + // send the notification in idle time to be sure it is sent after the change + // was fully done in wx code + const HWND hwnd = (HWND)window->GetHWND(); + SendNotification delayed((DWORD)eventType, hwnd, (LONG)objectType, (LONG)objectId); + wxTheApp->CallAfter(delayed); } // Utilities