From 09e923d965a86a944dad7d77b336721386f6bf63 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 10 Feb 2017 18:39:27 +0100 Subject: Return a list of events form native window instead of one event at a time. --- plugingui/nativewindow_win32.cc | 80 ++++++----------------------------------- 1 file changed, 10 insertions(+), 70 deletions(-) (limited to 'plugingui/nativewindow_win32.cc') diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index b81d121..3065b8c 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -30,7 +30,8 @@ #include "window.h" -namespace GUI { +namespace GUI +{ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) @@ -417,79 +418,18 @@ void NativeWindowWin32::grabMouse(bool grab) } } -bool NativeWindowWin32::hasEvent() -{ - if(!event_queue.empty()) - { - return true; - } - - // Parented windows have their event loop somewhere else. - if(parent_window == nullptr) - { - MSG msg; - return PeekMessage(&msg, m_hwnd, 0, 0, PM_NOREMOVE) != 0; - } - - return false; -} - -std::shared_ptr NativeWindowWin32::getNextEvent() +std::queue> NativeWindowWin32::getEvents() { - if(!event_queue.empty()) - { - auto event = event_queue.front(); - event_queue.pop(); - return event; - } - - // Parented windows have their event loop somewhere else. - if(parent_window == nullptr) - { - MSG msg; - if(GetMessage(&msg, m_hwnd, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - if(event_queue.empty()) - { - return nullptr; - } - - auto event = event_queue.front(); - event_queue.pop(); - return event; -} - -std::shared_ptr NativeWindowWin32::peekNextEvent() -{ - if(!event_queue.empty()) - { - auto event = event_queue.front(); - return event; - } - - // Parented windows have their event loop somewhere else. - if(parent_window == nullptr) - { - MSG msg; - if(PeekMessage(&msg, m_hwnd, 0, 0, PM_NOREMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - if(event_queue.empty()) + MSG msg; + while(PeekMessage(&msg, m_hwnd, 0, 0, PM_REMOVE) != 0) { - return nullptr; + TranslateMessage(&msg); + DispatchMessage(&msg); } - auto event = event_queue.front(); - return event; + std::queue> events; + std::swap(events, event_queue); + return events; } } // GUI:: -- cgit v1.2.3