https://git.reactos.org/?p=reactos.git;a=commitdiff;h=17bdf554743f08a32c940…
commit 17bdf554743f08a32c940a1185cef4fb5a05fc38
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Mon Jun 19 08:24:17 2023 +0900
Commit: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
CommitDate: Mon Jun 19 08:25:23 2023 +0900
[MSPAINT] Smartly restrict CTextEditWindow's size and position
...by using WM_SIZING and WM_MOVING. CORE-18867
---
base/applications/mspaint/selectionmodel.cpp | 1 +
base/applications/mspaint/selectionmodel.h | 2 +-
base/applications/mspaint/textedit.cpp | 117 +++++++++++++++++++++------
base/applications/mspaint/textedit.h | 5 +-
4 files changed, 97 insertions(+), 28 deletions(-)
diff --git a/base/applications/mspaint/selectionmodel.cpp
b/base/applications/mspaint/selectionmodel.cpp
index 1137453dd3f..fb28ad5033a 100644
--- a/base/applications/mspaint/selectionmodel.cpp
+++ b/base/applications/mspaint/selectionmodel.cpp
@@ -18,6 +18,7 @@ SelectionModel::SelectionModel()
, m_hbmMask(NULL)
, m_ptStack(NULL)
, m_iPtSP(0)
+ , m_rgbBack(RGB(255, 255, 255))
, m_bShow(FALSE)
, m_bContentChanged(FALSE)
{
diff --git a/base/applications/mspaint/selectionmodel.h
b/base/applications/mspaint/selectionmodel.h
index c2ec6bffbc2..230c87dfdf5 100644
--- a/base/applications/mspaint/selectionmodel.h
+++ b/base/applications/mspaint/selectionmodel.h
@@ -18,7 +18,7 @@ private:
int m_iPtSP;
public:
- COLORREF m_rgbBack = RGB(255, 255, 255);
+ COLORREF m_rgbBack;
BOOL m_bShow;
BOOL m_bContentChanged;
CRect m_rc; // in image pixel coordinates
diff --git a/base/applications/mspaint/textedit.cpp
b/base/applications/mspaint/textedit.cpp
index 6d84a12c285..8ec1155d1c9 100644
--- a/base/applications/mspaint/textedit.cpp
+++ b/base/applications/mspaint/textedit.cpp
@@ -200,12 +200,6 @@ LRESULT CTextEditWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM
lParam, BO
LRESULT CTextEditWindow::OnMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
LRESULT ret = DefWindowProc(nMsg, wParam, lParam);
-
- if (m_nAppIsMovingOrSizing == 0)
- {
- Reposition();
- InvalidateEditRect();
- }
return ret;
}
@@ -218,12 +212,6 @@ LRESULT CTextEditWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& b
SendMessage(EM_SETRECTNP, 0, (LPARAM)&rc);
SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0, 0));
- if (m_nAppIsMovingOrSizing == 0)
- {
- Reposition();
- InvalidateEditRect();
- }
-
return ret;
}
@@ -400,27 +388,104 @@ void CTextEditWindow::ValidateEditRect(LPCRECT prc OPTIONAL)
--m_nAppIsMovingOrSizing;
}
-void CTextEditWindow::Reposition()
+LRESULT CTextEditWindow::OnMoving(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
- CRect rc;
- GetWindowRect(&rc);
- ::MapWindowPoints(NULL, canvasWindow, (LPPOINT)&rc, 2);
- canvasWindow.CanvasToImage(rc);
+ // Restrict the window position to the image area
+ LPRECT prcMoving = (LPRECT)lParam;
+ CRect rcMoving = *prcMoving;
CRect rcImage;
canvasWindow.GetImageRect(rcImage);
+ canvasWindow.ImageToCanvas(rcImage);
+ canvasWindow.MapWindowPoints(NULL, &rcImage);
- // FIXME: Smartly restrict the position and size by using WM_WINDOWPOSCHANGING
- if (rc.left < 0)
- ::OffsetRect(&rc, -rc.left, 0);
- if (rc.top < 0)
- ::OffsetRect(&rc, 0, -rc.top);
+ CRect rcWnd;
+ GetWindowRect(&rcWnd);
+ INT cx = rcWnd.Width(), cy = rcWnd.Height();
- canvasWindow.ImageToCanvas(rc);
+ if (rcMoving.left < rcImage.left)
+ {
+ rcMoving.left = rcImage.left;
+ rcMoving.right = rcImage.left + cx;
+ }
+ else if (rcMoving.right > rcImage.right)
+ {
+ rcMoving.right = rcImage.right;
+ rcMoving.left = rcImage.right - cx;
+ }
- ++m_nAppIsMovingOrSizing;
- MoveWindow(rc.left, rc.top, rc.Width(), rc.Height(), TRUE);
- --m_nAppIsMovingOrSizing;
+ if (rcMoving.top < rcImage.top)
+ {
+ rcMoving.top = rcImage.top;
+ rcMoving.bottom = rcImage.top + cy;
+ }
+ else if (rcMoving.bottom > rcImage.bottom)
+ {
+ rcMoving.bottom = rcImage.bottom;
+ rcMoving.top = rcImage.bottom - cy;
+ }
+
+ *prcMoving = rcMoving;
+ Invalidate(TRUE);
+ return TRUE;
+}
+
+LRESULT CTextEditWindow::OnSizing(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
+{
+ // Restrict the window size to the image area
+ LPRECT prcSizing = (LPRECT)lParam;
+ CRect rcSizing = *prcSizing;
+
+ CRect rcImage;
+ canvasWindow.GetImageRect(rcImage);
+ canvasWindow.ImageToCanvas(rcImage);
+ canvasWindow.MapWindowPoints(NULL, &rcImage);
+
+ // Horizontally
+ switch (wParam)
+ {
+ case WMSZ_BOTTOMLEFT:
+ case WMSZ_LEFT:
+ case WMSZ_TOPLEFT:
+ if (rcSizing.left < rcImage.left)
+ rcSizing.left = rcImage.left;
+ break;
+ case WMSZ_BOTTOMRIGHT:
+ case WMSZ_RIGHT:
+ case WMSZ_TOPRIGHT:
+ if (rcSizing.right > rcImage.right)
+ rcSizing.right = rcImage.right;
+ break;
+ case WMSZ_TOP:
+ case WMSZ_BOTTOM:
+ default:
+ break;
+ }
+
+ // Vertically
+ switch (wParam)
+ {
+ case WMSZ_BOTTOM:
+ case WMSZ_BOTTOMLEFT:
+ case WMSZ_BOTTOMRIGHT:
+ if (rcSizing.bottom > rcImage.bottom)
+ rcSizing.bottom = rcImage.bottom;
+ break;
+ case WMSZ_TOP:
+ case WMSZ_TOPLEFT:
+ case WMSZ_TOPRIGHT:
+ if (rcSizing.top < rcImage.top)
+ rcSizing.top = rcImage.top;
+ break;
+ case WMSZ_LEFT:
+ case WMSZ_RIGHT:
+ default:
+ break;
+ }
+
+ *prcSizing = rcSizing;
+ Invalidate(TRUE);
+ return TRUE;
}
LRESULT CTextEditWindow::OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
diff --git a/base/applications/mspaint/textedit.h b/base/applications/mspaint/textedit.h
index 95fb3e6ca45..7060919cae6 100644
--- a/base/applications/mspaint/textedit.h
+++ b/base/applications/mspaint/textedit.h
@@ -32,6 +32,8 @@ public:
MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged)
MESSAGE_HANDLER(WM_TOOLSMODELZOOMCHANGED, OnToolsModelZoomChanged)
MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged)
+ MESSAGE_HANDLER(WM_MOVING, OnMoving)
+ MESSAGE_HANDLER(WM_SIZING, OnSizing)
MESSAGE_HANDLER(WM_CHAR, OnChar)
MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkGnd)
@@ -56,6 +58,8 @@ public:
LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandled);
LRESULT OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled);
LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled);
+ LRESULT OnMoving(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+ LRESULT OnSizing(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnChar(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -82,5 +86,4 @@ protected:
INT DoHitTest(RECT& rc, POINT pt);
void DrawGrip(HDC hDC, RECT& rc);
- void Reposition();
};