mirror of
https://github.com/reactos/reactos.git
synced 2025-04-05 13:11:22 +00:00
[MSPAINT] Smartly restrict CTextEditWindow's size and position
...by using WM_SIZING and WM_MOVING. CORE-18867
This commit is contained in:
parent
7aadc1e1fe
commit
17bdf55474
4 changed files with 97 additions and 28 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue