[MSPAINT] Allow paletteWindow to be bottom-aligned (#5216)

The user will be able to move the palette window to bottom by dragging.
- Add Bar1ID registry setting.
- Move paletteWindow to top or bottom in mainWindow's WM_SIZE handling.
- Track the mouse dragging on paletteWindow.
- If the dragging is beyond the center point, then move paletteWindow.
CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-04-04 19:06:06 +09:00 committed by GitHub
parent ccef43f3b0
commit d0c657074d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 6 deletions

View file

@ -132,6 +132,7 @@ LRESULT CPaletteWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, B
INT iColor = DoHitTest(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
if (iColor != -1)
paletteModel.SetFgColor(paletteModel.GetColor(iColor));
SetCapture();
return 0;
}
@ -178,3 +179,36 @@ LRESULT CPaletteWindow::OnPaletteModelPaletteChanged(UINT nMsg, WPARAM wParam, L
InvalidateRect(NULL, FALSE);
return 0;
}
LRESULT CPaletteWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (::GetCapture() != m_hWnd)
return 0;
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ClientToScreen(&pt);
RECT rc;
mainWindow.GetWindowRect(&rc);
POINT ptCenter = { (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2 };
DWORD dwExpectedBar1ID = ((pt.y < ptCenter.y) ? BAR1ID_TOP : BAR1ID_BOTTOM);
if (registrySettings.Bar1ID != dwExpectedBar1ID)
{
registrySettings.Bar1ID = dwExpectedBar1ID;
mainWindow.PostMessage(WM_SIZE, 0, 0);
}
return 0;
}
LRESULT CPaletteWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (::GetCapture() != m_hWnd)
return 0;
::ReleaseCapture();
return 0;
}

View file

@ -24,6 +24,8 @@ public:
MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk)
MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnRButtonDblClk)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged)
MESSAGE_HANDLER(WM_PALETTEMODELPALETTECHANGED, OnPaletteModelPaletteChanged)
END_MSG_MAP()
@ -34,6 +36,8 @@ public:
LRESULT OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteModelPaletteChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

View file

@ -75,6 +75,7 @@ void RegistrySettings::LoadPresets(INT nCmdShow)
ShowStatusBar = TRUE;
ShowPalette = TRUE;
ShowToolBox = TRUE;
Bar1ID = BAR1ID_TOP;
Bar2ID = BAR2ID_LEFT;
LOGFONT lf;
@ -142,6 +143,12 @@ void RegistrySettings::Load(INT nCmdShow)
ReadString(text, _T("TypeFaceName"), strFontName, strFontName);
}
CRegKey bar1;
if (bar1.Open(paint, _T("General-Bar1"), KEY_READ) == ERROR_SUCCESS)
{
ReadDWORD(bar1, _T("BarID"), Bar1ID);
}
CRegKey bar2;
if (bar2.Open(paint, _T("General-Bar2"), KEY_READ) == ERROR_SUCCESS)
{
@ -220,6 +227,12 @@ void RegistrySettings::Store()
text.SetStringValue(_T("TypeFaceName"), strFontName);
}
CRegKey bar1;
if (bar1.Create(paint, _T("General-Bar1")) == ERROR_SUCCESS)
{
bar1.SetDWORDValue(_T("BarID"), Bar1ID);
}
CRegKey bar2;
if (bar2.Create(paint, _T("General-Bar2")) == ERROR_SUCCESS)
{

View file

@ -43,8 +43,14 @@ public:
DWORD ShowStatusBar;
DWORD ShowPalette;
DWORD ShowToolBox;
DWORD Bar1ID;
DWORD Bar2ID;
// Values for Bar1ID.
// I think these values are Win2k3 mspaint compatible but sometimes not working...
#define BAR1ID_TOP 0x0000e81b
#define BAR1ID_BOTTOM 0x0000e81e
// Values for Bar2ID.
// I think these values are Win2k3 mspaint compatible but sometimes not working...
#define BAR2ID_LEFT 0x0000e81c

View file

@ -147,7 +147,7 @@ LRESULT CToolBox::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
RECT rc;
mainWindow.GetWindowRect(&rc);
POINT ptCenter = { (rc.left + rc.right) / 2, (rc.bottom - rc.top) / 2 };
POINT ptCenter = { (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2 };
DWORD dwExpectedBar2ID = ((pt.x < ptCenter.x) ? BAR2ID_LEFT : BAR2ID_RIGHT);

View file

@ -108,11 +108,22 @@ void CMainWindow::alignChildrenToMainWindow()
if (::IsWindowVisible(paletteWindow))
{
hDWP = ::DeferWindowPos(hDWP, paletteWindow, NULL,
rcSpace.left, rcSpace.top,
rcSpace.right - rcSpace.left, CY_PALETTE,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION);
rcSpace.top += CY_PALETTE;
if (registrySettings.Bar1ID == BAR1ID_BOTTOM)
{
hDWP = ::DeferWindowPos(hDWP, paletteWindow, NULL,
rcSpace.left, rcSpace.bottom - CY_PALETTE,
rcSpace.right - rcSpace.left, CY_PALETTE,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION);
rcSpace.bottom -= CY_PALETTE;
}
else
{
hDWP = ::DeferWindowPos(hDWP, paletteWindow, NULL,
rcSpace.left, rcSpace.top,
rcSpace.right - rcSpace.left, CY_PALETTE,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION);
rcSpace.top += CY_PALETTE;
}
}
if (canvasWindow.IsWindow())