summaryrefslogtreecommitdiff
path: root/plugingui/nativewindow_win32.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2017-02-10 18:39:27 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2017-02-10 18:39:27 +0100
commit09e923d965a86a944dad7d77b336721386f6bf63 (patch)
tree1000abf99b16bb6d70d8d88f1cd26096b634b027 /plugingui/nativewindow_win32.cc
parent53fa1c76c27726670f2724793d867d817c029709 (diff)
Return a list of events form native window instead of one event at a time.
Diffstat (limited to 'plugingui/nativewindow_win32.cc')
-rw-r--r--plugingui/nativewindow_win32.cc80
1 files changed, 10 insertions, 70 deletions
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<Event> NativeWindowWin32::getNextEvent()
+std::queue<std::shared_ptr<Event>> 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<Event> 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<std::shared_ptr<Event>> events;
+ std::swap(events, event_queue);
+ return events;
}
} // GUI::