[WIN32SS][NTUSER] Refactor PR #1226 (#1266)

Refactoring of #1226. CORE-12845
This commit is contained in:
Katayama Hirofumi MZ 2019-01-19 23:56:33 +09:00 committed by GitHub
parent c3e4b5fec6
commit d0d909245f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -783,85 +783,84 @@ IntDefWindowProc(
} }
if (IS_KEY_DOWN(gafAsyncKeyState, VK_LWIN) || IS_KEY_DOWN(gafAsyncKeyState, VK_RWIN)) if (IS_KEY_DOWN(gafAsyncKeyState, VK_LWIN) || IS_KEY_DOWN(gafAsyncKeyState, VK_RWIN))
{ {
PWND topWnd = UserGetWindowObject(UserGetForegroundWindow()); HWND hwndTop = UserGetForegroundWindow();
PWND topWnd = UserGetWindowObject(hwndTop);
if (topWnd) if (topWnd)
{ {
if (wParam == VK_DOWN) if (wParam == VK_DOWN)
{ {
co_IntSendMessage(UserHMGetHandle(topWnd), WM_SYSCOMMAND, (topWnd->style & WS_MAXIMIZE) ? SC_RESTORE : SC_MINIMIZE, lParam); if (topWnd->style & WS_MAXIMIZE)
} co_IntSendMessage(hwndTop, WM_SYSCOMMAND, SC_RESTORE, lParam);
else else
if (wParam == VK_UP) co_IntSendMessage(hwndTop, WM_SYSCOMMAND, SC_MINIMIZE, lParam);
}
else if (wParam == VK_UP)
{ {
RECT currentRect = (topWnd->InternalPos.NormalRect.right == topWnd->InternalPos.NormalRect.left) || RECT currentRect;
(topWnd->InternalPos.NormalRect.top == topWnd->InternalPos.NormalRect.bottom) if ((topWnd->InternalPos.NormalRect.right == topWnd->InternalPos.NormalRect.left) ||
? topWnd->rcWindow (topWnd->InternalPos.NormalRect.top == topWnd->InternalPos.NormalRect.bottom))
: topWnd->InternalPos.NormalRect; {
co_IntSendMessage(UserHMGetHandle(topWnd), WM_SYSCOMMAND, SC_MAXIMIZE, 0); currentRect = topWnd->rcWindow;
}
else
{
currentRect = topWnd->InternalPos.NormalRect;
}
co_IntSendMessage(hwndTop, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
// save normal rect if maximazing snapped window // save normal rect if maximazing snapped window
topWnd->InternalPos.NormalRect = currentRect; topWnd->InternalPos.NormalRect = currentRect;
} }
else else if (wParam == VK_LEFT || wParam == VK_RIGHT)
if (wParam == VK_LEFT || wParam == VK_RIGHT)
{ {
RECT snapRect; RECT snapRect, normalRect, windowRect;
RECT normalRect; BOOL snapped;
RECT windowRect;
BOOL snapped = FALSE;
normalRect = topWnd->InternalPos.NormalRect; normalRect = topWnd->InternalPos.NormalRect;
snapped = (normalRect.left != 0 snapped = (normalRect.left != 0 && normalRect.right != 0 &&
&& normalRect.right != 0 normalRect.top != 0 && normalRect.bottom != 0);
&& normalRect.top != 0
&& normalRect.bottom != 0);
if (topWnd->style & WS_MAXIMIZE) if (topWnd->style & WS_MAXIMIZE)
{ {
co_IntSendMessage(UserHMGetHandle(topWnd), WM_SYSCOMMAND, SC_RESTORE, lParam); co_IntSendMessage(hwndTop, WM_SYSCOMMAND, SC_RESTORE, lParam);
snapped = FALSE; snapped = FALSE;
} }
windowRect = topWnd->rcWindow; windowRect = topWnd->rcWindow;
UserSystemParametersInfo(SPI_GETWORKAREA, 0, &snapRect, 0); UserSystemParametersInfo(SPI_GETWORKAREA, 0, &snapRect, 0);
if (wParam == VK_LEFT) if (wParam == VK_LEFT)
{ {
snapRect.right = (snapRect.right - snapRect.left) / 2 + snapRect.left; snapRect.right = (snapRect.left + snapRect.right) / 2;
} }
else // VK_RIGHT else // VK_RIGHT
{ {
snapRect.left = (snapRect.right - snapRect.left) / 2 + snapRect.left; snapRect.left = (snapRect.left + snapRect.right) / 2;
} }
if (snapped) if (snapped)
{ {
// if window was snapped but moved to other location - restore normal size // if window was snapped but moved to other location - restore normal size
if (snapRect.left != windowRect.left || if (!IntEqualRect(&snapRect, &windowRect))
snapRect.right != windowRect.right ||
snapRect.top != windowRect.top ||
snapRect.bottom != windowRect.bottom)
{ {
RECT empty = {0, 0, 0, 0}; RECT empty = {0, 0, 0, 0};
co_WinPosSetWindowPos(topWnd, co_WinPosSetWindowPos(topWnd,
0, 0,
normalRect.left, normalRect.left,
normalRect.top, normalRect.top,
normalRect.right - normalRect.left, normalRect.right - normalRect.left,
normalRect.bottom - normalRect.top, normalRect.bottom - normalRect.top,
0); 0);
topWnd->InternalPos.NormalRect = empty; topWnd->InternalPos.NormalRect = empty;
} }
} }
else else
{ {
co_WinPosSetWindowPos(topWnd, co_WinPosSetWindowPos(topWnd,
0, 0,
snapRect.left, snapRect.left,
snapRect.top, snapRect.top,
snapRect.right - snapRect.left, snapRect.right - snapRect.left,
snapRect.bottom - snapRect.top, snapRect.bottom - snapRect.top,
0); 0);
topWnd->InternalPos.NormalRect = windowRect; topWnd->InternalPos.NormalRect = windowRect;
} }
} }