refactor(new_editor/app): reorganize host structure and add smoke test
This commit is contained in:
@@ -1,155 +0,0 @@
|
||||
#include "WindowMessageDispatcher.h"
|
||||
|
||||
#include "../Application.h"
|
||||
|
||||
namespace XCEngine::UI::Editor::Host {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr UINT kMessageNcUaDrawCaption = 0x00AEu;
|
||||
constexpr UINT kMessageNcUaDrawFrame = 0x00AFu;
|
||||
|
||||
} // namespace
|
||||
|
||||
void TryEnableNonClientDpiScaling(HWND hwnd) {
|
||||
if (hwnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const HMODULE user32 = GetModuleHandleW(L"user32.dll");
|
||||
if (user32 == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
using EnableNonClientDpiScalingFn = BOOL(WINAPI*)(HWND);
|
||||
const auto enableNonClientDpiScaling =
|
||||
reinterpret_cast<EnableNonClientDpiScalingFn>(
|
||||
GetProcAddress(user32, "EnableNonClientDpiScaling"));
|
||||
if (enableNonClientDpiScaling != nullptr) {
|
||||
enableNonClientDpiScaling(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
Application* WindowMessageDispatcher::GetApplicationFromWindow(HWND hwnd) {
|
||||
return reinterpret_cast<Application*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
}
|
||||
|
||||
bool WindowMessageDispatcher::TryHandleNonClientCreate(
|
||||
HWND hwnd,
|
||||
UINT message,
|
||||
LPARAM lParam,
|
||||
LRESULT& outResult) {
|
||||
if (message != WM_NCCREATE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TryEnableNonClientDpiScaling(hwnd);
|
||||
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
|
||||
auto* application = reinterpret_cast<Application*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(application));
|
||||
outResult = TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WindowMessageDispatcher::TryDispatch(
|
||||
HWND hwnd,
|
||||
Application& application,
|
||||
UINT message,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam,
|
||||
LRESULT& outResult) {
|
||||
const auto renderAndValidateWindow = [&application, hwnd]() {
|
||||
if (!application.m_renderReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
application.RenderFrame();
|
||||
if (hwnd != nullptr && IsWindow(hwnd)) {
|
||||
ValidateRect(hwnd, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
switch (message) {
|
||||
case WM_GETMINMAXINFO:
|
||||
if (application.IsBorderlessWindowEnabled() &&
|
||||
application.HandleBorderlessWindowGetMinMaxInfo(lParam)) {
|
||||
outResult = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WM_NCCALCSIZE:
|
||||
if (application.IsBorderlessWindowEnabled()) {
|
||||
outResult = application.HandleBorderlessWindowNcCalcSize(wParam, lParam);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WM_NCACTIVATE:
|
||||
if (application.IsBorderlessWindowEnabled()) {
|
||||
outResult = TRUE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WM_NCHITTEST:
|
||||
if (application.IsBorderlessWindowEnabled()) {
|
||||
outResult = HTCLIENT;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WM_NCPAINT:
|
||||
case kMessageNcUaDrawCaption:
|
||||
case kMessageNcUaDrawFrame:
|
||||
if (application.IsBorderlessWindowEnabled()) {
|
||||
outResult = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WM_SYSCOMMAND:
|
||||
if (application.HandleBorderlessWindowSystemCommand(wParam)) {
|
||||
outResult = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WM_SETCURSOR:
|
||||
if (LOWORD(lParam) == HTCLIENT && application.ApplyCurrentCursor()) {
|
||||
outResult = TRUE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case WM_DPICHANGED:
|
||||
if (lParam == 0) {
|
||||
return false;
|
||||
}
|
||||
application.OnDpiChanged(
|
||||
static_cast<UINT>(LOWORD(wParam)),
|
||||
*reinterpret_cast<const RECT*>(lParam));
|
||||
renderAndValidateWindow();
|
||||
outResult = 0;
|
||||
return true;
|
||||
case WM_ENTERSIZEMOVE:
|
||||
application.OnEnterSizeMove();
|
||||
outResult = 0;
|
||||
return true;
|
||||
case WM_EXITSIZEMOVE:
|
||||
application.OnExitSizeMove();
|
||||
renderAndValidateWindow();
|
||||
outResult = 0;
|
||||
return true;
|
||||
case WM_SIZE:
|
||||
if (wParam != SIZE_MINIMIZED) {
|
||||
application.OnResize(
|
||||
static_cast<UINT>(LOWORD(lParam)),
|
||||
static_cast<UINT>(HIWORD(lParam)));
|
||||
renderAndValidateWindow();
|
||||
}
|
||||
outResult = 0;
|
||||
return true;
|
||||
case WM_PAINT:
|
||||
application.OnPaintMessage();
|
||||
outResult = 0;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Host
|
||||
Reference in New Issue
Block a user