From 15faa626f7df7a3024dda5d11001347ed4573568 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 9 May 2019 20:52:43 +0200 Subject: Add tooltip buttons to frames. --- plugingui/nativewindow_win32.cc | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'plugingui/nativewindow_win32.cc') diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index 5cfb179..0dc30de 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -35,6 +35,16 @@ namespace GUI { +static BOOL trackMouse(HWND hwnd) +{ + TRACKMOUSEEVENT ev{}; + ev.cbSize = sizeof(ev); + ev.dwFlags = TME_HOVER | TME_LEAVE; + ev.hwndTrack = hwnd; + ev.dwHoverTime = 1; + return TrackMouseEvent(&ev); +} + LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { @@ -89,9 +99,20 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, // return 0; case WM_MOUSEMOVE: { + trackMouse(native->m_hwnd); auto mouseMoveEvent = std::make_shared(); mouseMoveEvent->x = (short)LOWORD(lp); mouseMoveEvent->y = (short)HIWORD(lp); + native->last_mouse_position = { mouseMoveEvent->x, mouseMoveEvent->y }; + + if(!native->mouse_in_window) + { + auto enterEvent = std::make_shared(); + enterEvent->x = native->last_mouse_position.first; + enterEvent->y = native->last_mouse_position.second; + native->event_queue.push_back(enterEvent); + native->mouse_in_window = true; + } native->event_queue.push_back(mouseMoveEvent); } break; @@ -295,8 +316,17 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, DeleteObject(ourbitmap); } } + break; - return DefWindowProc(hwnd, msg, wp, lp); + case WM_MOUSELEAVE: + { + auto leaveEvent = std::make_shared(); + leaveEvent->x = native->last_mouse_position.first; + leaveEvent->y = native->last_mouse_position.second; + native->event_queue.push_back(leaveEvent); + native->mouse_in_window = false; + } + break; } return DefWindowProc(hwnd, msg, wp, lp); @@ -391,6 +421,9 @@ NativeWindowWin32::NativeWindowWin32(void* native_window, Window& window) GetModuleHandle(nullptr), nullptr); SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); + + // Set up initial tracking of the mouse leave events + trackMouse(m_hwnd); } NativeWindowWin32::~NativeWindowWin32() -- cgit v1.2.3