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
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ForceRefreshSelectionContents()
|
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
if (selectionWindow.IsWindowVisible())
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
selectionWindow.SendMessage(WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0));
|
|
|
|
selectionWindow.SendMessage(WM_MOUSEMOVE, 0, MAKELPARAM(0, 0));
|
|
|
|
selectionWindow.SendMessage(WM_LBUTTONUP, 0, MAKELPARAM(0, 0));
|
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
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iYPos < 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iXPos < 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_TOP_LEFT;
|
2015-07-09 09:48:01 +00:00
|
|
|
if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1))
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_TOP;
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iXPos >= iWidth - 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_TOP_RIGHT;
|
|
|
|
}
|
2015-07-09 09:48:01 +00:00
|
|
|
if ((iYPos < iHeight / 2 + 2) && (iYPos >= iHeight / 2 - 1))
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iXPos < 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_LEFT;
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iXPos >= iWidth - 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_RIGHT;
|
|
|
|
}
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iYPos >= iHeight - 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iXPos < 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_BOTTOM_LEFT;
|
2015-07-09 09:48:01 +00:00
|
|
|
if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1))
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_BOTTOM;
|
2015-07-09 09:48:01 +00:00
|
|
|
if (iXPos >= iWidth - 3)
|
2015-05-08 16:02:36 +00:00
|
|
|
return ACTION_RESIZE_BOTTOM_RIGHT;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (!m_bMoving)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
HDC hDC = GetDC();
|
|
|
|
DefWindowProc(WM_PAINT, wParam, lParam);
|
2015-07-09 09:48:01 +00:00
|
|
|
SelectionFrame(hDC, 1, 1, selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 5,
|
|
|
|
selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 5,
|
|
|
|
m_dwSystemSelectionColor);
|
2015-07-07 10:42:49 +00:00
|
|
|
ReleaseDC(hDC);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
// do nothing => transparent background
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2015-07-09 09:48:01 +00:00
|
|
|
m_dwSystemSelectionColor = GetSysColor(COLOR_HIGHLIGHT);
|
2015-07-07 10:42:49 +00:00
|
|
|
SendMessage(WM_PAINT, 0, MAKELPARAM(0, 0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
/* update the system selection color */
|
2015-07-09 09:48:01 +00:00
|
|
|
m_dwSystemSelectionColor = GetSysColor(COLOR_HIGHLIGHT);
|
2015-07-07 10:42:49 +00:00
|
|
|
SendMessage(WM_PAINT, 0, MAKELPARAM(0, 0));
|
|
|
|
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);
|
|
|
|
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();
|
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;
|
|
|
|
m_ptDelta.x += m_ptFrac.x * 1000 / toolsModel.GetZoom();
|
|
|
|
m_ptDelta.y += m_ptFrac.y * 1000 / toolsModel.GetZoom();
|
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
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
m_ptFrac.x -= (m_ptFrac.x * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000;
|
|
|
|
m_ptFrac.y -= (m_ptFrac.y * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000;
|
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
|
|
|
|
2015-07-07 11:15:24 +00:00
|
|
|
if (toolsModel.GetActiveTool() == TOOL_TEXT)
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
2015-07-23 13:52:02 +00:00
|
|
|
selectionModel.DrawTextToolText(imageModel.GetDC(), paletteModel.GetFgColor(), paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent());
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
if (m_iAction != ACTION_MOVE)
|
2015-07-23 13:52:02 +00:00
|
|
|
selectionModel.DrawSelectionStretched(imageModel.GetDC());
|
2015-05-08 16:02:36 +00:00
|
|
|
else
|
2015-07-23 13:52:02 +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
|
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
int w = selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 6;
|
|
|
|
int h = selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 6;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2015-07-09 09:48:01 +00:00
|
|
|
if (m_iAction != ACTION_MOVE)
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
2015-07-07 11:15:24 +00:00
|
|
|
if (toolsModel.GetActiveTool() == TOOL_TEXT)
|
2015-07-07 10:42:49 +00:00
|
|
|
{
|
|
|
|
// FIXME: What to do?
|
|
|
|
}
|
|
|
|
else
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-09 09:48:01 +00:00
|
|
|
selectionModel.ScaleContentsToFit();
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
|
|
|
placeSelWin();
|
|
|
|
ShowWindow(SW_HIDE);
|
|
|
|
ShowWindow(SW_SHOW);
|
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)
|
|
|
|
{
|
|
|
|
// FIXME: dirty hack
|
|
|
|
placeSelWin();
|
|
|
|
imageModel.Undo();
|
|
|
|
imageModel.Undo();
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (toolsModel.GetActiveTool() == TOOL_TEXT)
|
|
|
|
ForceRefreshSelectionContents();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (toolsModel.GetActiveTool() == TOOL_FREESEL ||
|
|
|
|
toolsModel.GetActiveTool() == TOOL_RECTSEL ||
|
|
|
|
toolsModel.GetActiveTool() == TOOL_TEXT)
|
|
|
|
ForceRefreshSelectionContents();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CSelectionWindow::OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
ForceRefreshSelectionContents();
|
|
|
|
return 0;
|
|
|
|
}
|