From 75a7fc6d0e667653ff1135490bdc37aeda172b4a Mon Sep 17 00:00:00 2001 From: Chris Anselmo Date: Mon, 26 May 2025 13:37:14 -0400 Subject: [PATCH] New: Window.minimizable and Window.maximizable properties --- src/core/ui/Window.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/core/ui/Window.c b/src/core/ui/Window.c index 0f51fce..d1ba9dc 100644 --- a/src/core/ui/Window.c +++ b/src/core/ui/Window.c @@ -515,6 +515,18 @@ LUA_PROPERTY_GET(Window, topmost) { return 1; } +LUA_PROPERTY_GET(Window, maximizable) { + Widget *w = lua_self(L, 1, Widget); + lua_pushboolean(L, GetWindowLongPtr(w->handle, GWL_STYLE) & WS_MAXIMIZEBOX); + return 1; +} + +LUA_PROPERTY_GET(Window, minimizable) { + Widget *w = lua_self(L, 1, Widget); + lua_pushboolean(L, GetWindowLongPtr(w->handle, GWL_STYLE) & WS_MINIMIZEBOX); + return 1; +} + LUA_PROPERTY_SET(Window, topmost) { SetWindowPos(lua_self(L, 1, Widget)->handle, lua_toboolean(L, 2) ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); return 0; @@ -544,6 +556,30 @@ LUA_PROPERTY_SET(Window, fullscreen) { return 0; } +LUA_PROPERTY_SET(Window, maximizable) { + Widget *w = lua_self(L, 1, Widget); + HWND h = w->handle; + int ismaximizable = lua_toboolean(L, 2); + if (ismaximizable) { + SetWindowLongPtr(h, GWL_STYLE, GetWindowLongPtr(h, GWL_STYLE) | WS_MAXIMIZEBOX); + } else { + SetWindowLongPtr(h, GWL_STYLE, GetWindowLongPtr(h, GWL_STYLE) & ~WS_MAXIMIZEBOX); + } + return 0; +} + +LUA_PROPERTY_SET(Window, minimizable) { + Widget *w = lua_self(L, 1, Widget); + HWND h = w->handle; + int isminimizable = lua_toboolean(L, 2); + if (isminimizable) { + SetWindowLongPtr(h, GWL_STYLE, GetWindowLongPtr(h, GWL_STYLE) | WS_MINIMIZEBOX); + } else { + SetWindowLongPtr(h, GWL_STYLE, GetWindowLongPtr(h, GWL_STYLE) & ~WS_MINIMIZEBOX); + } + return 0; +} + static int notify(lua_State *L, Widget *w, DWORD action, UINT flags, void *tip, wchar_t *info, DWORD niif) { NOTIFYICONDATAW nid = {0}; BOOL result = FALSE; @@ -825,6 +861,8 @@ OBJECT_MEMBERS(Window) METHOD(Widget, center) METHOD(Window, notify) METHOD(Window, startmoving) + READWRITE_PROPERTY(Window, maximizable) + READWRITE_PROPERTY(Window, minimizable) READWRITE_PROPERTY(Window, traytooltip) READWRITE_PROPERTY(Window, fullscreen) READWRITE_PROPERTY(Window, topmost)