2015-05-08 16:02:36 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/mspaint/selection.cpp
|
2015-05-08 16:02:36 +00:00
|
|
|
* PURPOSE: Window procedure of the selection window
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
2017-07-27 09:29:42 +00:00
|
|
|
* Katayama Hirofumi MZ
|
2015-05-08 16:02:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
2015-07-09 09:48:01 +00:00
|
|
|
const LPCTSTR CSelectionWindow::m_lpszCursorLUT[9] = { /* action to mouse cursor lookup table */
|
2015-05-08 16:02:36 +00:00
|
|
|
IDC_SIZEALL,
|
|
|
|
|
|
|
|
IDC_SIZENWSE, IDC_SIZENS, IDC_SIZENESW,
|
|
|
|
IDC_SIZEWE, IDC_SIZEWE,
|
|
|
|
IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE
|
|
|
|
};
|
|
|
|
|
|
|
|
BOOL
|
2022-01-10 12:44:13 +00:00
|
|
|
ColorKeyedMaskBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
|
|
|
|
HDC hdcSrc, int nXSrc, int nYSrc, HBITMAP hbmMask, int xMask, int yMask,
|
|
|
|
DWORD dwRop, COLORREF keyColor)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
|
|
|
HDC hTempDC;
|
|
|
|
HDC hTempDC2;
|
|
|
|
HBITMAP hTempBm;
|
|
|
|
HBRUSH hTempBrush;
|
|
|
|
HBITMAP hTempMask;
|
|
|
|
|
|
|
|
hTempDC = CreateCompatibleDC(hdcSrc);
|
|
|
|
hTempDC2 = CreateCompatibleDC(hdcSrc);
|
|
|
|
hTempBm = CreateCompatibleBitmap(hTempDC, nWidth, nHeight);
|
|
|
|
SelectObject(hTempDC, hTempBm);
|
|
|
|
hTempBrush = CreateSolidBrush(keyColor);
|
|
|
|
SelectObject(hTempDC, hTempBrush);
|
|
|
|
BitBlt(hTempDC, 0, 0, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, SRCCOPY);
|
|
|
|
PatBlt(hTempDC, 0, 0, nWidth, nHeight, PATINVERT);
|
|
|
|
hTempMask = CreateBitmap(nWidth, nHeight, 1, 1, NULL);
|
|
|
|
SelectObject(hTempDC2, hTempMask);
|
|
|
|
BitBlt(hTempDC2, 0, 0, nWidth, nHeight, hTempDC, 0, 0, SRCCOPY);
|
|
|
|
SelectObject(hTempDC, hbmMask);
|
|
|
|
BitBlt(hTempDC2, 0, 0, nWidth, nHeight, hTempDC, xMask, yMask, SRCAND);
|
|
|
|
MaskBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, hTempMask, xMask, yMask, dwRop);
|
|
|
|
DeleteDC(hTempDC);
|
|
|
|
DeleteDC(hTempDC2);
|
|
|
|
DeleteObject(hTempBm);
|
|
|
|
DeleteObject(hTempBrush);
|
|
|
|
DeleteObject(hTempMask);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-01-30 03:05:23 +00:00
|
|
|
void CSelectionWindow::ForceRefreshSelectionContents()
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2022-01-22 15:59:12 +00:00
|
|
|
if (::IsWindowVisible(selectionWindow))
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
imageModel.ResetToPrevious();
|
|
|
|
imageModel.DrawSelectionBackground(m_rgbBack);
|
|
|
|
selectionModel.DrawSelection(imageModel.GetDC(), paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent());
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 09:48:01 +00:00
|
|
|
int CSelectionWindow::IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2021-12-26 14:05:47 +00:00
|
|
|
POINT pt = { iXPos, iYPos };
|
|
|
|
HWND hwndChild = ChildWindowFromPointEx(pt, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED);
|
|
|
|
if (hwndChild == sizeboxLeftTop)
|
|
|
|
return ACTION_RESIZE_TOP_LEFT;
|
|
|
|
if (hwndChild == sizeboxCenterTop)
|
|
|
|
return ACTION_RESIZE_TOP;
|
|
|
|
if (hwndChild == sizeboxRightTop)
|
|
|
|
return ACTION_RESIZE_TOP_RIGHT;
|
|
|
|
if (hwndChild == sizeboxRightCenter)
|
|
|
|
return ACTION_RESIZE_RIGHT;
|
|
|
|
if (hwndChild == sizeboxLeftCenter)
|
|
|
|
return ACTION_RESIZE_LEFT;
|
|
|
|
if (hwndChild == sizeboxCenterBottom)
|
|
|
|
return ACTION_RESIZE_BOTTOM;
|
|
|
|
if (hwndChild == sizeboxRightBottom)
|
|
|
|
return ACTION_RESIZE_BOTTOM_RIGHT;
|
|
|
|
if (hwndChild == sizeboxLeftBottom)
|
|
|
|
return ACTION_RESIZE_BOTTOM_LEFT;
|
2015-05-08 16:02:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CSelectionWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hDC = BeginPaint(&ps);
|
2015-07-09 09:48:01 +00:00
|
|
|
if (!m_bMoving)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2022-01-10 12:44:13 +00:00
|
|
|
SelectionFrame(hDC, 1, 1,
|
|
|
|
Zoomed(selectionModel.GetDestRectWidth()) + (GRIP_SIZE * 2) - 1,
|
|
|
|
Zoomed(selectionModel.GetDestRectHeight()) + (GRIP_SIZE * 2) - 1,
|
|
|
|
GetSysColor(COLOR_HIGHLIGHT));
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
2022-01-30 03:05:23 +00:00
|
|
|
EndPaint(&ps);
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
// do nothing => transparent background
|
2022-01-10 12:44:13 +00:00
|
|
|
return TRUE;
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
m_bMoving = FALSE;
|
|
|
|
m_iAction = ACTION_MOVE;
|
2015-07-07 10:42:49 +00:00
|
|
|
/* update the system selection color */
|
2022-01-10 12:44:13 +00:00
|
|
|
Invalidate();
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
/* update the system selection color */
|
2022-01-10 12:44:13 +00:00
|
|
|
Invalidate();
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
SetCursor(LoadCursor(NULL, IDC_SIZEALL));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
m_ptPos.x = GET_X_LPARAM(lParam);
|
|
|
|
m_ptPos.y = GET_Y_LPARAM(lParam);
|
|
|
|
m_ptDelta.x = 0;
|
|
|
|
m_ptDelta.y = 0;
|
2015-07-07 10:42:49 +00:00
|
|
|
SetCapture();
|
2015-07-09 09:48:01 +00:00
|
|
|
if (m_iAction != ACTION_MOVE)
|
|
|
|
SetCursor(LoadCursor(NULL, m_lpszCursorLUT[m_iAction]));
|
|
|
|
m_bMoving = TRUE;
|
2015-07-07 10:42:49 +00:00
|
|
|
scrlClientWindow.InvalidateRect(NULL, TRUE);
|
2018-05-26 11:23:20 +00:00
|
|
|
scrlClientWindow.SendMessage(WM_PAINT, 0, 0);
|
|
|
|
imageArea.InvalidateRect(NULL, FALSE);
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.SendMessage(WM_PAINT, 0, 0);
|
2022-01-30 03:05:23 +00:00
|
|
|
m_rgbBack = paletteModel.GetBgColor();
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (m_bMoving)
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
2015-07-07 11:56:37 +00:00
|
|
|
imageModel.ResetToPrevious();
|
2022-01-30 03:05:23 +00:00
|
|
|
imageModel.DrawSelectionBackground(m_rgbBack);
|
2015-07-09 09:48:01 +00:00
|
|
|
m_ptFrac.x += GET_X_LPARAM(lParam) - m_ptPos.x;
|
|
|
|
m_ptFrac.y += GET_Y_LPARAM(lParam) - m_ptPos.y;
|
2021-12-26 10:49:56 +00:00
|
|
|
m_ptDelta.x += UnZoomed(m_ptFrac.x);
|
|
|
|
m_ptDelta.y += UnZoomed(m_ptFrac.y);
|
2015-07-07 11:15:24 +00:00
|
|
|
if (toolsModel.GetZoom() < 1000)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
m_ptFrac.x = 0;
|
|
|
|
m_ptFrac.y = 0;
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
else
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2021-12-26 10:49:56 +00:00
|
|
|
m_ptFrac.x -= Zoomed(UnZoomed(m_ptFrac.x));
|
|
|
|
m_ptFrac.y -= Zoomed(UnZoomed(m_ptFrac.y));
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-09 09:48:01 +00:00
|
|
|
selectionModel.ModifyDestRect(m_ptDelta, m_iAction);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2016-10-09 11:42:37 +00:00
|
|
|
CString strSize;
|
2019-12-24 04:29:29 +00:00
|
|
|
strSize.Format(_T("%ld x %ld"), selectionModel.GetDestRectWidth(), selectionModel.GetDestRectHeight());
|
2016-10-09 11:42:37 +00:00
|
|
|
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2022-01-30 03:05:23 +00:00
|
|
|
if (m_iAction != ACTION_MOVE)
|
|
|
|
selectionModel.DrawSelectionStretched(imageModel.GetDC());
|
2015-07-07 10:42:49 +00:00
|
|
|
else
|
2022-01-30 03:05:23 +00:00
|
|
|
selectionModel.DrawSelection(imageModel.GetDC(), paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent());
|
2015-07-07 10:42:49 +00:00
|
|
|
imageArea.InvalidateRect(NULL, FALSE);
|
|
|
|
imageArea.SendMessage(WM_PAINT, 0, 0);
|
2015-07-09 09:48:01 +00:00
|
|
|
m_ptPos.x = GET_X_LPARAM(lParam);
|
|
|
|
m_ptPos.y = GET_Y_LPARAM(lParam);
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-26 14:05:47 +00:00
|
|
|
int w = Zoomed(selectionModel.GetDestRectWidth()) + 2 * GRIP_SIZE;
|
|
|
|
int h = Zoomed(selectionModel.GetDestRectHeight()) + 2 * GRIP_SIZE;
|
2015-07-09 09:48:01 +00:00
|
|
|
m_ptPos.x = GET_X_LPARAM(lParam);
|
|
|
|
m_ptPos.y = GET_Y_LPARAM(lParam);
|
2015-07-07 10:42:49 +00:00
|
|
|
SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);
|
2015-07-09 09:48:01 +00:00
|
|
|
m_iAction = IdentifyCorner(m_ptPos.x, m_ptPos.y, w, h);
|
|
|
|
if (m_iAction != ACTION_MOVE)
|
|
|
|
SetCursor(LoadCursor(NULL, m_lpszCursorLUT[m_iAction]));
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-30 03:05:23 +00:00
|
|
|
LRESULT CSelectionWindow::OnMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
m_bMoved = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CSelectionWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (m_bMoving)
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
m_bMoving = FALSE;
|
2015-07-07 10:42:49 +00:00
|
|
|
ReleaseCapture();
|
2022-01-30 03:05:23 +00:00
|
|
|
if (m_iAction != ACTION_MOVE && toolsModel.GetActiveTool() != TOOL_TEXT)
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
imageModel.Undo();
|
|
|
|
imageModel.DrawSelectionBackground(m_rgbBack);
|
|
|
|
selectionModel.ScaleContentsToFit();
|
|
|
|
imageModel.CopyPrevious();
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
placeSelWin();
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-09 18:48:42 +00:00
|
|
|
|
2017-07-27 09:29:42 +00:00
|
|
|
LRESULT CSelectionWindow::OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (m_bMoving)
|
|
|
|
{
|
|
|
|
m_bMoving = FALSE;
|
|
|
|
if (m_iAction == ACTION_MOVE)
|
|
|
|
{
|
2022-01-30 03:05:23 +00:00
|
|
|
if (toolsModel.GetActiveTool() == TOOL_RECTSEL)
|
|
|
|
imageArea.cancelDrawing();
|
|
|
|
else
|
|
|
|
placeSelWin();
|
2017-07-27 09:29:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_iAction = ACTION_MOVE;
|
|
|
|
}
|
|
|
|
ShowWindow(SW_HIDE);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (wParam == VK_ESCAPE)
|
|
|
|
{
|
|
|
|
if (GetCapture() == m_hWnd)
|
|
|
|
{
|
|
|
|
ReleaseCapture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:48:42 +00:00
|
|
|
LRESULT CSelectionWindow::OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2022-02-14 03:08:34 +00:00
|
|
|
ForceRefreshSelectionContents();
|
2015-07-09 18:48:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-27 13:20:22 +00:00
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
return ::SendMessage(GetParent(), nMsg, wParam, lParam);
|
|
|
|
}
|
2022-01-10 12:41:00 +00:00
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
placeSelWin();
|
|
|
|
return 0;
|
|
|
|
}
|