port: MSWindow/MSApplication verbatim over a winuser.h shim (Win32User.cpp)
Host-side window records + message queue; WM_SIZE/WM_MOVE/WM_DESTROY sent synchronously as Win32 does; PostQuitMessage also queues WM_QUIT. 64-bit pointer casts ADAPTED. port.ms_window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
80c5a1e39f
commit
5d64311a4d
@@ -1,49 +1,58 @@
|
||||
// Platform skeleton for EterLib/MSApplication.h (40250 EterLib/MSApplication.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 EterLib/MSApplication.cpp, verbatim over the <winuser.h> subset of platform/Win32User.cpp.
|
||||
// ClearWindowClass is declared in MSApplication.h but not defined in 40250.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/MSApplication.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
CMSApplication::CMSApplication()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CMSApplication::~CMSApplication()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
// for (TWindowClassSet::iterator i=ms_stWCSet.begin(); i!=ms_stWCSet.end(); ++i)
|
||||
// UnregisterClass(*i, ms_hInstance);
|
||||
}
|
||||
|
||||
auto CMSApplication::Initialize(HINSTANCE) -> void
|
||||
void CMSApplication::Initialize(HINSTANCE hInstance)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
ms_hInstance = hInstance;
|
||||
}
|
||||
|
||||
auto CMSApplication::MessageLoop() -> void
|
||||
void CMSApplication::MessageLoop()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
while (MessageProcess());
|
||||
}
|
||||
|
||||
auto CMSApplication::IsMessage() -> bool
|
||||
bool CMSApplication::IsMessage()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
MSG msg;
|
||||
|
||||
if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CMSApplication::MessageProcess() -> bool
|
||||
bool CMSApplication::MessageProcess()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
MSG msg;
|
||||
|
||||
if (!GetMessage(&msg, NULL, 0, 0))
|
||||
return false;
|
||||
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CMSApplication::ClearWindowClass() -> void
|
||||
LRESULT CMSApplication::WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
switch (uiMsg)
|
||||
{
|
||||
case WM_CLOSE:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
|
||||
auto CMSApplication::WindowProcedure(HWND, UINT, WPARAM, LPARAM) -> LRESULT
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<LRESULT>();
|
||||
return CMSWindow::WindowProcedure(hWnd, uiMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
+243
-139
@@ -1,150 +1,254 @@
|
||||
// Platform skeleton for EterLib/MSWindow.h (40250 EterLib/MSWindow.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 EterLib/MSWindow.cpp, verbatim over the <winuser.h> subset of platform/Win32User.cpp, except the
|
||||
// two pointer-to-DWORD casts (PORT below), which do not fit a 64-bit pointer.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/MSWindow.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
#include "HostCursor.h"
|
||||
#include <windowsx.h>
|
||||
|
||||
CMSWindow::TWindowClassSet CMSWindow::ms_stWCSet;
|
||||
HINSTANCE CMSWindow::ms_hInstance = NULL;
|
||||
|
||||
LRESULT CALLBACK MSWindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// PORT: 40250 reads GetWindowLong(GWL_USERDATA), the 32-bit pointer SetWindowLong stored in Create.
|
||||
CMSWindow * pWnd = (CMSWindow *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
|
||||
if (pWnd)
|
||||
return pWnd->WindowProcedure(hWnd, uiMsg, wParam, lParam);
|
||||
|
||||
return DefWindowProc(hWnd, uiMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
LRESULT CMSWindow::WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (uiMsg)
|
||||
{
|
||||
case WM_SIZE:
|
||||
OnSize(wParam, lParam);
|
||||
break;
|
||||
|
||||
case WM_ACTIVATEAPP:
|
||||
m_isActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, uiMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
void CMSWindow::OnSize(WPARAM wParam, LPARAM /*lParam*/)
|
||||
{
|
||||
if (wParam == SIZE_MINIMIZED)
|
||||
{
|
||||
InvalidateRect(m_hWnd, NULL, true);
|
||||
m_isActive = false;
|
||||
m_isVisible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_isActive = true;
|
||||
m_isVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CMSWindow::Destroy()
|
||||
{
|
||||
if (!m_hWnd)
|
||||
return;
|
||||
|
||||
if (IsWindow(m_hWnd))
|
||||
DestroyWindow(m_hWnd);
|
||||
|
||||
m_hWnd = NULL;
|
||||
m_isVisible = false;
|
||||
}
|
||||
|
||||
bool CMSWindow::Create(const char* c_szName, int brush, DWORD cs, DWORD ws, HICON hIcon, int iCursorResource)
|
||||
{
|
||||
//assert(ms_hInstance != NULL);
|
||||
Destroy();
|
||||
|
||||
const char* c_szClassName = RegisterWindowClass(cs, brush, MSWindowProcedure, hIcon, iCursorResource);
|
||||
|
||||
m_hWnd = CreateWindow(
|
||||
c_szClassName,
|
||||
c_szName,
|
||||
ws,
|
||||
0, 0, 0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
ms_hInstance,
|
||||
NULL);
|
||||
|
||||
if (!m_hWnd)
|
||||
return false;
|
||||
|
||||
// PORT: 40250 stores (DWORD) this with SetWindowLong(GWL_USERDATA); a 64-bit pointer needs the LONG_PTR slot.
|
||||
SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG_PTR) this);
|
||||
//DestroyWindow(ImmGetDefaultIMEWnd(m_hWnd));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMSWindow::SetVisibleMode(bool isVisible)
|
||||
{
|
||||
m_isVisible = isVisible;
|
||||
|
||||
if (m_isVisible)
|
||||
{
|
||||
ShowWindow(m_hWnd, SW_SHOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWindow(m_hWnd, SW_HIDE);
|
||||
}
|
||||
}
|
||||
|
||||
void CMSWindow::Show()
|
||||
{
|
||||
m_isVisible = true;
|
||||
ShowWindow(m_hWnd, SW_SHOW);
|
||||
}
|
||||
|
||||
void CMSWindow::Hide()
|
||||
{
|
||||
m_isVisible = false;
|
||||
ShowWindow(m_hWnd, SW_HIDE);
|
||||
}
|
||||
|
||||
bool CMSWindow::IsVisible()
|
||||
{
|
||||
return m_isVisible;
|
||||
}
|
||||
|
||||
bool CMSWindow::IsActive()
|
||||
{
|
||||
return m_isActive;
|
||||
}
|
||||
|
||||
HINSTANCE CMSWindow::GetInstance()
|
||||
{
|
||||
return ms_hInstance;
|
||||
}
|
||||
|
||||
HWND CMSWindow::GetWindowHandle()
|
||||
{
|
||||
return m_hWnd;
|
||||
}
|
||||
|
||||
int CMSWindow::GetScreenWidth()
|
||||
{
|
||||
return GetSystemMetrics(SM_CXSCREEN);
|
||||
}
|
||||
|
||||
int CMSWindow::GetScreenHeight()
|
||||
{
|
||||
return GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
||||
|
||||
void CMSWindow::GetWindowRect(RECT* prc)
|
||||
{
|
||||
::GetWindowRect(m_hWnd, prc);
|
||||
}
|
||||
|
||||
|
||||
void CMSWindow::GetClientRect(RECT* prc)
|
||||
{
|
||||
::GetClientRect(m_hWnd, prc);
|
||||
}
|
||||
|
||||
void CMSWindow::GetMousePosition(POINT* ppt)
|
||||
{
|
||||
GetCursorPos(ppt);
|
||||
ScreenToClient(m_hWnd, ppt);
|
||||
}
|
||||
|
||||
void CMSWindow::SetPosition(int x, int y)
|
||||
{
|
||||
SetWindowPos(m_hWnd, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
|
||||
}
|
||||
|
||||
void CMSWindow::SetCenterPosition()
|
||||
{
|
||||
RECT rc;
|
||||
|
||||
GetClientRect(&rc);
|
||||
|
||||
int windowWidth = rc.right - rc.left;
|
||||
int windowHeight = rc.bottom - rc.top;
|
||||
|
||||
SetPosition((GetScreenWidth()-windowWidth)/2, (GetScreenHeight()-windowHeight)/2);
|
||||
}
|
||||
|
||||
void CMSWindow::AdjustSize(int width, int height)
|
||||
{
|
||||
SetRect(&m_rect, 0, 0, width, height);
|
||||
|
||||
AdjustWindowRectEx(&m_rect,
|
||||
GetWindowStyle(m_hWnd),
|
||||
GetMenu(m_hWnd ) != NULL,
|
||||
GetWindowExStyle(m_hWnd ) );
|
||||
|
||||
MoveWindow
|
||||
(
|
||||
m_hWnd,
|
||||
0,
|
||||
0,
|
||||
m_rect.right - m_rect.left,
|
||||
m_rect.bottom - m_rect.top,
|
||||
FALSE
|
||||
);
|
||||
}
|
||||
|
||||
void CMSWindow::SetText(const char* c_szText)
|
||||
{
|
||||
SetWindowText(m_hWnd, c_szText);
|
||||
}
|
||||
|
||||
void CMSWindow::SetSize(int width, int height)
|
||||
{
|
||||
SetWindowPos(m_hWnd, NULL, 0, 0, width, height, SWP_NOZORDER|SWP_NOMOVE);
|
||||
}
|
||||
|
||||
const char * CMSWindow::RegisterWindowClass(DWORD style, int brush, WNDPROC pfnWndProc, HICON hIcon, int iCursorResource)
|
||||
{
|
||||
char szClassName[1024];
|
||||
// PORT: 40250 casts the procedure straight to DWORD; the low 32 bits of the 64-bit address, as there.
|
||||
sprintf(szClassName, "eter - s%x:b%x:p:%x", style, brush, (DWORD) (uintptr_t) pfnWndProc);
|
||||
|
||||
TWindowClassSet::iterator f = ms_stWCSet.find((char*) szClassName);
|
||||
|
||||
if (f != ms_stWCSet.end())
|
||||
return *f;
|
||||
|
||||
const char* c_szStaticClassName = stl_static_string(szClassName).c_str();
|
||||
|
||||
ms_stWCSet.insert((char * const) c_szStaticClassName);
|
||||
|
||||
WNDCLASS wc;
|
||||
|
||||
wc.style = 0;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.lpfnWndProc = pfnWndProc;
|
||||
wc.hCursor = LoadCursor(ms_hInstance, MAKEINTRESOURCE(iCursorResource));
|
||||
wc.hIcon = hIcon ? hIcon : LoadIcon(ms_hInstance, IDI_APPLICATION);
|
||||
wc.hbrBackground = (HBRUSH) GetStockObject(brush);
|
||||
wc.hInstance = ms_hInstance;
|
||||
wc.lpszClassName = c_szStaticClassName;
|
||||
wc.lpszMenuName = "";
|
||||
|
||||
if (!RegisterClass(&wc))
|
||||
return "";
|
||||
|
||||
return c_szStaticClassName;
|
||||
}
|
||||
|
||||
CMSWindow::CMSWindow()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
m_hWnd=NULL;
|
||||
m_isVisible=false;
|
||||
}
|
||||
|
||||
CMSWindow::~CMSWindow()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::Destroy() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::Create(const char *, int, DWORD, DWORD, HICON, int) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CMSWindow::Show() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::Hide() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::SetVisibleMode(bool) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::SetPosition(int, int) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::SetCenterPosition() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::SetText(const char *) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::AdjustSize(int, int) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::SetSize(int, int) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::IsVisible() -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CMSWindow::IsActive() -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
namespace {
|
||||
POINT g_host_cursor = {0, 0};
|
||||
}
|
||||
|
||||
void MtHostSetCursor(int x, int y)
|
||||
{
|
||||
g_host_cursor.x = x;
|
||||
g_host_cursor.y = y;
|
||||
}
|
||||
|
||||
auto CMSWindow::GetMousePosition(POINT * ppt) -> void
|
||||
{
|
||||
*ppt = g_host_cursor;
|
||||
}
|
||||
|
||||
auto CMSWindow::GetClientRect(RECT *) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::GetWindowRect(RECT *) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::GetScreenWidth() -> int
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
}
|
||||
|
||||
auto CMSWindow::GetScreenHeight() -> int
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
}
|
||||
|
||||
auto CMSWindow::GetWindowHandle() -> HWND
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<HWND>();
|
||||
}
|
||||
|
||||
auto CMSWindow::GetInstance() -> HINSTANCE
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<HINSTANCE>();
|
||||
}
|
||||
|
||||
auto CMSWindow::WindowProcedure(HWND, UINT, WPARAM, LPARAM) -> LRESULT
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<LRESULT>();
|
||||
}
|
||||
|
||||
auto CMSWindow::OnSize(WPARAM, LPARAM) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CMSWindow::RegisterWindowClass(DWORD, int, WNDPROC, HICON, int) -> const char *
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<const char *>();
|
||||
}
|
||||
|
||||
decltype(CMSWindow::ms_stWCSet) CMSWindow::ms_stWCSet{};
|
||||
|
||||
decltype(CMSWindow::ms_hInstance) CMSWindow::ms_hInstance{};
|
||||
|
||||
Reference in New Issue
Block a user