FluentUI/src/NativeEventFilter.cpp

82 lines
3.0 KiB
C++
Raw Normal View History

2023-04-11 23:12:31 +08:00
#include "NativeEventFilter.h"
#include "FluTheme.h"
#include "FluApp.h"
#ifdef Q_OS_WIN
2023-04-22 19:25:10 +08:00
#pragma comment(lib, "Dwmapi.lib")
#pragma comment(lib, "User32.lib")
2023-04-11 23:12:31 +08:00
#include <Windows.h>
#include <windowsx.h>
#endif
bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
{
#ifdef Q_OS_WIN
2023-04-27 09:38:57 +08:00
if (eventType == "windows_generic_MSG" && FluApp::fluTheme->frameless()) {
2023-04-19 09:41:08 +08:00
MSG* msg = static_cast<MSG *>(message);
if (msg == Q_NULLPTR)
return false;
2023-04-27 09:38:57 +08:00
if(!FluApp::fluApp->wnds.contains((WId)msg->hwnd)){
2023-04-24 17:02:26 +08:00
return false;
}
2023-04-19 09:41:08 +08:00
switch(msg->message) {
case WM_NCCALCSIZE:{
NCCALCSIZE_PARAMS& params = *reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam);
if (params.rgrc[0].top != 0)
params.rgrc[0].top -= 1;
*result = WVR_REDRAW;
return true;
}
case WM_NCHITTEST: {
2023-04-27 09:38:57 +08:00
auto view = FluApp::fluApp->wnds[(WId)msg->hwnd];
2023-04-19 09:41:08 +08:00
bool isResize = !(view->maximumWidth()==view->minimumWidth()&&view->maximumHeight()==view->minimumHeight());
const LONG borderWidth = 8;
RECT winrect;
GetWindowRect(msg->hwnd, &winrect);
long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam);
if (x >= winrect.left && x < winrect.left + borderWidth &&
y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
*result = HTBOTTOMLEFT;
2023-04-11 23:12:31 +08:00
return true;
}
2023-04-19 09:41:08 +08:00
if (x < winrect.right && x >= winrect.right - borderWidth &&
2023-04-11 23:12:31 +08:00
y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
2023-04-19 09:41:08 +08:00
*result = HTBOTTOMRIGHT;
return true;
}
if (x >= winrect.left && x < winrect.left + borderWidth &&
2023-04-11 23:12:31 +08:00
y >= winrect.top && y < winrect.top + borderWidth && isResize) {
2023-04-19 09:41:08 +08:00
*result = HTTOPLEFT;
return true;
}
if (x < winrect.right && x >= winrect.right - borderWidth &&
2023-04-11 23:12:31 +08:00
y >= winrect.top && y < winrect.top + borderWidth && isResize) {
2023-04-19 09:41:08 +08:00
*result = HTTOPRIGHT;
return true;
2023-04-11 23:12:31 +08:00
}
2023-04-19 09:41:08 +08:00
if (x >= winrect.left && x < winrect.left + borderWidth && isResize) {
*result = HTLEFT;
return true;
}
if (x < winrect.right && x >= winrect.right - borderWidth && isResize) {
*result = HTRIGHT;
return true;
}
if (y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
*result = HTBOTTOM;
return true;
}
if (y >= winrect.top && y < winrect.top + borderWidth && isResize) {
*result = HTTOP;
return true;
2023-04-11 23:12:31 +08:00
}
2023-04-19 09:41:08 +08:00
return false;
}
default:
break;
2023-04-11 23:12:31 +08:00
}
2023-04-19 09:41:08 +08:00
}
2023-04-11 23:12:31 +08:00
#endif
return false;
}