ReactOS  0.4.12-dev-57-g7050ac4
selection.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: PAINT for ReactOS
3  * LICENSE: LGPL
4  * FILE: base/applications/mspaint/selection.cpp
5  * PURPOSE: Window procedure of the selection window
6  * PROGRAMMERS: Benedikt Freisen
7  * Katayama Hirofumi MZ
8  */
9 
10 /* INCLUDES *********************************************************/
11 
12 #include "precomp.h"
13 
14 /* FUNCTIONS ********************************************************/
15 
16 const LPCTSTR CSelectionWindow::m_lpszCursorLUT[9] = { /* action to mouse cursor lookup table */
18 
21  IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE
22 };
23 
24 BOOL
25 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)
26 {
27  HDC hTempDC;
28  HDC hTempDC2;
29  HBITMAP hTempBm;
30  HBRUSH hTempBrush;
31  HBITMAP hTempMask;
32 
33  hTempDC = CreateCompatibleDC(hdcSrc);
34  hTempDC2 = CreateCompatibleDC(hdcSrc);
35  hTempBm = CreateCompatibleBitmap(hTempDC, nWidth, nHeight);
36  SelectObject(hTempDC, hTempBm);
37  hTempBrush = CreateSolidBrush(keyColor);
38  SelectObject(hTempDC, hTempBrush);
39  BitBlt(hTempDC, 0, 0, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, SRCCOPY);
40  PatBlt(hTempDC, 0, 0, nWidth, nHeight, PATINVERT);
41  hTempMask = CreateBitmap(nWidth, nHeight, 1, 1, NULL);
42  SelectObject(hTempDC2, hTempMask);
43  BitBlt(hTempDC2, 0, 0, nWidth, nHeight, hTempDC, 0, 0, SRCCOPY);
44  SelectObject(hTempDC, hbmMask);
45  BitBlt(hTempDC2, 0, 0, nWidth, nHeight, hTempDC, xMask, yMask, SRCAND);
46  MaskBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, hTempMask, xMask, yMask, dwRop);
47  DeleteDC(hTempDC);
48  DeleteDC(hTempDC2);
49  DeleteObject(hTempBm);
50  DeleteObject(hTempBrush);
51  DeleteObject(hTempMask);
52  return TRUE;
53 }
54 
55 void
57 {
58  if (selectionWindow.IsWindowVisible())
59  {
60  selectionWindow.SendMessage(WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0));
61  selectionWindow.SendMessage(WM_MOUSEMOVE, 0, MAKELPARAM(0, 0));
62  selectionWindow.SendMessage(WM_LBUTTONUP, 0, MAKELPARAM(0, 0));
63  }
64 }
65 
66 int CSelectionWindow::IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight)
67 {
68  if (iYPos < 3)
69  {
70  if (iXPos < 3)
72  if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1))
73  return ACTION_RESIZE_TOP;
74  if (iXPos >= iWidth - 3)
76  }
77  if ((iYPos < iHeight / 2 + 2) && (iYPos >= iHeight / 2 - 1))
78  {
79  if (iXPos < 3)
80  return ACTION_RESIZE_LEFT;
81  if (iXPos >= iWidth - 3)
82  return ACTION_RESIZE_RIGHT;
83  }
84  if (iYPos >= iHeight - 3)
85  {
86  if (iXPos < 3)
88  if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1))
89  return ACTION_RESIZE_BOTTOM;
90  if (iXPos >= iWidth - 3)
92  }
93  return 0;
94 }
95 
97 {
98  if (!m_bMoving)
99  {
100  HDC hDC = GetDC();
101  DefWindowProc(WM_PAINT, wParam, lParam);
105  ReleaseDC(hDC);
106  }
107  return 0;
108 }
109 
111 {
112  // do nothing => transparent background
113  return 0;
114 }
115 
117 {
118  m_bMoving = FALSE;
120  /* update the system selection color */
122  SendMessage(WM_PAINT, 0, MAKELPARAM(0, 0));
123  return 0;
124 }
125 
127 {
128  /* update the system selection color */
130  SendMessage(WM_PAINT, 0, MAKELPARAM(0, 0));
131  return 0;
132 }
133 
135 {
137  return 0;
138 }
139 
141 {
142  m_ptPos.x = GET_X_LPARAM(lParam);
143  m_ptPos.y = GET_Y_LPARAM(lParam);
144  m_ptDelta.x = 0;
145  m_ptDelta.y = 0;
146  SetCapture();
147  if (m_iAction != ACTION_MOVE)
149  m_bMoving = TRUE;
150  scrlClientWindow.InvalidateRect(NULL, TRUE);
151  scrlClientWindow.SendMessage(WM_PAINT, 0, 0);
154  return 0;
155 }
156 
158 {
159  if (m_bMoving)
160  {
162  m_ptFrac.x += GET_X_LPARAM(lParam) - m_ptPos.x;
163  m_ptFrac.y += GET_Y_LPARAM(lParam) - m_ptPos.y;
164  m_ptDelta.x += m_ptFrac.x * 1000 / toolsModel.GetZoom();
165  m_ptDelta.y += m_ptFrac.y * 1000 / toolsModel.GetZoom();
166  if (toolsModel.GetZoom() < 1000)
167  {
168  m_ptFrac.x = 0;
169  m_ptFrac.y = 0;
170  }
171  else
172  {
173  m_ptFrac.x -= (m_ptFrac.x * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000;
174  m_ptFrac.y -= (m_ptFrac.y * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000;
175  }
177 
178  CString strSize;
180  SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
181 
183  {
185  }
186  else
187  {
188  if (m_iAction != ACTION_MOVE)
190  else
192  }
195  m_ptPos.x = GET_X_LPARAM(lParam);
196  m_ptPos.y = GET_Y_LPARAM(lParam);
197  }
198  else
199  {
200  int w = selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 6;
201  int h = selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 6;
202  m_ptPos.x = GET_X_LPARAM(lParam);
203  m_ptPos.y = GET_Y_LPARAM(lParam);
206  if (m_iAction != ACTION_MOVE)
208  }
209  return 0;
210 }
211 
213 {
214  if (m_bMoving)
215  {
216  m_bMoving = FALSE;
217  ReleaseCapture();
218  if (m_iAction != ACTION_MOVE)
219  {
221  {
222  // FIXME: What to do?
223  }
224  else
225  {
227  }
228  }
229  placeSelWin();
232  }
233  return 0;
234 }
235 
237 {
238  if (m_bMoving)
239  {
240  m_bMoving = FALSE;
241  if (m_iAction == ACTION_MOVE)
242  {
243  // FIXME: dirty hack
244  placeSelWin();
245  imageModel.Undo();
246  imageModel.Undo();
247  }
248  else
249  {
251  }
253  }
254  return 0;
255 }
256 
258 {
259  if (wParam == VK_ESCAPE)
260  {
261  if (GetCapture() == m_hWnd)
262  {
263  ReleaseCapture();
264  }
265  }
266  return 0;
267 }
268 
270 {
273  return 0;
274 }
275 
277 {
282  return 0;
283 }
284 
286 {
288  return 0;
289 }
#define IDC_SIZEWE
Definition: winuser.h:689
void DrawSelectionStretched(HDC hDCImage)
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:140
#define HDC
Definition: msvc.h:22
ToolsModel toolsModel
Definition: main.cpp:18
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define COLOR_HIGHLIGHT
Definition: winuser.h:916
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
#define PATINVERT
Definition: wingdi.h:326
#define HBITMAP
Definition: msvc.h:28
long y
Definition: polytest.cpp:48
#define TOOL_TEXT
Definition: definitions.h:144
#define WM_LBUTTONDOWN
Definition: winuser.h:1752
long x
Definition: polytest.cpp:48
LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:276
#define ACTION_RESIZE_TOP_LEFT
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
#define SW_HIDE
Definition: winuser.h:762
#define MAKELPARAM(l, h)
Definition: winuser.h:3915
LRESULT OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:285
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:236
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:668
#define ACTION_RESIZE_RIGHT
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
SelectionModel selectionModel
Definition: main.cpp:20
DWORD m_dwSystemSelectionColor
Definition: selection.h:54
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
static HDC hdcSrc
Definition: xlate.c:32
LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:212
#define VK_ESCAPE
Definition: winuser.h:2168
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
#define IDC_SIZENESW
Definition: winuser.h:688
DWORD WINAPI GetSysColor(_In_ int)
WPARAM wParam
Definition: combotst.c:138
#define IDC_SIZENS
Definition: winuser.h:690
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
int GetZoom()
Definition: toolsmodel.cpp:104
UINT_PTR WPARAM
Definition: windef.h:207
BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase=TRUE)
Definition: atlwin.h:825
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
CImgAreaWindow imageArea
Definition: main.cpp:71
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:96
#define ACTION_RESIZE_BOTTOM_LEFT
#define IDC_SIZENWSE
Definition: winuser.h:687
LONG_PTR LPARAM
Definition: windef.h:208
HDC GetDC()
Definition: history.cpp:219
HWND WINAPI GetCapture(void)
Definition: message.c:2855
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
#define GET_X_LPARAM(lp)
Definition: precomp.h:67
#define ACTION_RESIZE_TOP_RIGHT
#define SW_SHOW
Definition: winuser.h:769
#define DefWindowProc
Definition: ros2win.h:31
BOOL IsBackgroundTransparent()
Definition: toolsmodel.cpp:93
CScrollboxWindow scrlClientWindow
Definition: main.cpp:69
void ModifyDestRect(POINT &ptDelta, int iAction)
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ACTION_MOVE
unsigned int UINT
Definition: ndis.h:50
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND hStatusBar
Definition: main.cpp:35
#define ACTION_RESIZE_TOP
LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:269
#define WM_PAINT
Definition: winuser.h:1602
void placeSelWin()
Definition: mouse.cpp:16
#define ACTION_RESIZE_LEFT
#define SB_SETTEXT
Definition: commctrl.h:1919
ImageModel imageModel
Definition: main.cpp:32
#define TOOL_FREESEL
Definition: definitions.h:135
#define TOOL_RECTSEL
Definition: definitions.h:136
#define LoadCursor
Definition: winuser.h:5678
void ForceRefreshSelectionContents()
Definition: selection.cpp:56
static HDC hDC
Definition: 3dtext.c:33
LRESULT OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:126
LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:257
HWND WINAPI SetCapture(_In_ HWND hWnd)
PaletteModel paletteModel
Definition: main.cpp:28
BOOL WINAPI DeleteDC(_In_ HDC)
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
int GetActiveTool()
Definition: toolsmodel.cpp:60
#define WM_LBUTTONUP
Definition: winuser.h:1753
LRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:110
#define IDC_SIZEALL
Definition: winuser.h:691
#define SRCAND
Definition: wingdi.h:328
#define WM_MOUSEMOVE
Definition: winuser.h:1751
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:116
void DrawSelection(HDC hDCImage, COLORREF crBg=0, BOOL bBgTransparent=FALSE)
#define GET_Y_LPARAM(lp)
Definition: precomp.h:68
static const LPCTSTR m_lpszCursorLUT[9]
Definition: selection.h:48
void Undo(void)
Definition: history.cpp:57
int IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight)
Definition: selection.cpp:66
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2864
#define SendMessage
Definition: winuser.h:5709
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1039
#define ACTION_RESIZE_BOTTOM
BOOL WINAPI MaskBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ HDC, _In_ int, _In_ int, _In_ HBITMAP, _In_ int, _In_ int, _In_ DWORD)
void DrawTextToolText(HDC hDCImage, COLORREF crFg, COLORREF crBg, BOOL bBgTransparent=FALSE)
LONG_PTR LRESULT
Definition: windef.h:209
#define ACTION_RESIZE_BOTTOM_RIGHT
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:157
DWORD COLORREF
Definition: windef.h:290
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)
Definition: selection.cpp:25
void ResetToPrevious(void)
Definition: history.cpp:93
LPARAM lParam
Definition: combotst.c:139
LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: selection.cpp:134
#define SRCCOPY
Definition: wingdi.h:331
void SelectionFrame(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, DWORD system_selection_color)
Definition: drawing.cpp:249
CSelectionWindow selectionWindow
Definition: main.cpp:70
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)