b5709d80bee2520481e5b72073bd7029fedc703b
[reactos.git] / reactos / base / applications / mspaint / sizebox.cpp
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint/sizebox.cpp
5 * PURPOSE: Window procedure of the size boxes
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "precomp.h"
12
13 /* FUNCTIONS ********************************************************/
14
15 static BOOL resizing = FALSE;
16 static short xOrig;
17 static short yOrig;
18
19 LRESULT CSizeboxWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
20 {
21 if ((m_hWnd == sizeboxLeftTop.m_hWnd) || (m_hWnd == sizeboxRightBottom.m_hWnd))
22 SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
23 if ((m_hWnd == sizeboxLeftBottom.m_hWnd) || (m_hWnd == sizeboxRightTop.m_hWnd))
24 SetCursor(LoadCursor(NULL, IDC_SIZENESW));
25 if ((m_hWnd == sizeboxLeftCenter.m_hWnd) || (m_hWnd == sizeboxRightCenter.m_hWnd))
26 SetCursor(LoadCursor(NULL, IDC_SIZEWE));
27 if ((m_hWnd == sizeboxCenterTop.m_hWnd) || (m_hWnd == sizeboxCenterBottom.m_hWnd))
28 SetCursor(LoadCursor(NULL, IDC_SIZENS));
29 return 0;
30 }
31
32 LRESULT CSizeboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
33 {
34 resizing = TRUE;
35 xOrig = GET_X_LPARAM(lParam);
36 yOrig = GET_Y_LPARAM(lParam);
37 SetCapture();
38 return 0;
39 }
40
41 LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
42 {
43 if (resizing)
44 {
45 CString strSize;
46 short xRel;
47 short yRel;
48 int imgXRes = imageModel.GetWidth();
49 int imgYRes = imageModel.GetHeight();
50 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
51 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
52 if (m_hWnd == sizeboxLeftTop.m_hWnd)
53 strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes - yRel);
54 if (m_hWnd == sizeboxCenterTop.m_hWnd)
55 strSize.Format(_T("%d x %d"), imgXRes, imgYRes - yRel);
56 if (m_hWnd == sizeboxRightTop.m_hWnd)
57 strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes - yRel);
58 if (m_hWnd == sizeboxLeftCenter.m_hWnd)
59 strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes);
60 if (m_hWnd == sizeboxRightCenter.m_hWnd)
61 strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes);
62 if (m_hWnd == sizeboxLeftBottom.m_hWnd)
63 strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes + yRel);
64 if (m_hWnd == sizeboxCenterBottom.m_hWnd)
65 strSize.Format(_T("%d x %d"), imgXRes, imgYRes + yRel);
66 if (m_hWnd == sizeboxRightBottom.m_hWnd)
67 strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes + yRel);
68 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
69 }
70 return 0;
71 }
72
73 LRESULT CSizeboxWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
74 {
75 if (resizing)
76 {
77 short xRel;
78 short yRel;
79 int imgXRes = imageModel.GetWidth();
80 int imgYRes = imageModel.GetHeight();
81 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom();
82 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom();
83 if (m_hWnd == sizeboxLeftTop)
84 imageModel.Crop(imgXRes - xRel, imgYRes - yRel, xRel, yRel);
85 if (m_hWnd == sizeboxCenterTop.m_hWnd)
86 imageModel.Crop(imgXRes, imgYRes - yRel, 0, yRel);
87 if (m_hWnd == sizeboxRightTop.m_hWnd)
88 imageModel.Crop(imgXRes + xRel, imgYRes - yRel, 0, yRel);
89 if (m_hWnd == sizeboxLeftCenter.m_hWnd)
90 imageModel.Crop(imgXRes - xRel, imgYRes, xRel, 0);
91 if (m_hWnd == sizeboxRightCenter.m_hWnd)
92 imageModel.Crop(imgXRes + xRel, imgYRes, 0, 0);
93 if (m_hWnd == sizeboxLeftBottom.m_hWnd)
94 imageModel.Crop(imgXRes - xRel, imgYRes + yRel, xRel, 0);
95 if (m_hWnd == sizeboxCenterBottom.m_hWnd)
96 imageModel.Crop(imgXRes, imgYRes + yRel, 0, 0);
97 if (m_hWnd == sizeboxRightBottom.m_hWnd)
98 imageModel.Crop(imgXRes + xRel, imgYRes + yRel, 0, 0);
99 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T(""));
100 }
101 ReleaseCapture();
102 resizing = FALSE;
103 return 0;
104 }
105
106 LRESULT CSizeboxWindow::OnCancelMode(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
107 {
108 resizing = FALSE;
109 return 0;
110 }