https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d0c657074dcfeefe2888c1c3569ad2d7822185c2

commit d0c657074dcfeefe2888c1c3569ad2d7822185c2
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Tue Apr 4 19:06:06 2023 +0900
Commit:     GitHub <[email protected]>
CommitDate: Tue Apr 4 19:06:06 2023 +0900

    [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
---
 base/applications/mspaint/palette.cpp  | 34 ++++++++++++++++++++++++++++++++++
 base/applications/mspaint/palette.h    |  4 ++++
 base/applications/mspaint/registry.cpp | 13 +++++++++++++
 base/applications/mspaint/registry.h   |  6 ++++++
 base/applications/mspaint/toolbox.cpp  |  2 +-
 base/applications/mspaint/winproc.cpp  | 21 ++++++++++++++++-----
 6 files changed, 74 insertions(+), 6 deletions(-)

diff --git a/base/applications/mspaint/palette.cpp 
b/base/applications/mspaint/palette.cpp
index 161d056ba92..920af27d250 100644
--- a/base/applications/mspaint/palette.cpp
+++ b/base/applications/mspaint/palette.cpp
@@ -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;
+}
diff --git a/base/applications/mspaint/palette.h 
b/base/applications/mspaint/palette.h
index 13a7b1663be..c9e09e92708 100644
--- a/base/applications/mspaint/palette.h
+++ b/base/applications/mspaint/palette.h
@@ -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);
 
diff --git a/base/applications/mspaint/registry.cpp 
b/base/applications/mspaint/registry.cpp
index 5a2b15121e3..ecff8a5df30 100644
--- a/base/applications/mspaint/registry.cpp
+++ b/base/applications/mspaint/registry.cpp
@@ -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)
     {
diff --git a/base/applications/mspaint/registry.h 
b/base/applications/mspaint/registry.h
index 7749328cd10..bc77c4b4423 100644
--- a/base/applications/mspaint/registry.h
+++ b/base/applications/mspaint/registry.h
@@ -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
diff --git a/base/applications/mspaint/toolbox.cpp 
b/base/applications/mspaint/toolbox.cpp
index c7a4667ac87..7e772a5bb6c 100644
--- a/base/applications/mspaint/toolbox.cpp
+++ b/base/applications/mspaint/toolbox.cpp
@@ -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);
 
diff --git a/base/applications/mspaint/winproc.cpp 
b/base/applications/mspaint/winproc.cpp
index 66e29e742b3..c709750b2e3 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -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())

Reply via email to