- Update to r53061
[reactos.git] / base / applications / mspaint / sizebox.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: sizebox.c
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 BOOL resizing = FALSE;
16 short xOrig;
17 short yOrig;
18
19 LRESULT CALLBACK
20 SizeboxWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
21 {
22 switch (message)
23 {
24 case WM_SETCURSOR:
25 if ((hwnd == hSizeboxLeftTop) || (hwnd == hSizeboxRightBottom))
26 SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
27 if ((hwnd == hSizeboxLeftBottom) || (hwnd == hSizeboxRightTop))
28 SetCursor(LoadCursor(NULL, IDC_SIZENESW));
29 if ((hwnd == hSizeboxLeftCenter) || (hwnd == hSizeboxRightCenter))
30 SetCursor(LoadCursor(NULL, IDC_SIZEWE));
31 if ((hwnd == hSizeboxCenterTop) || (hwnd == hSizeboxCenterBottom))
32 SetCursor(LoadCursor(NULL, IDC_SIZENS));
33 break;
34 case WM_LBUTTONDOWN:
35 resizing = TRUE;
36 xOrig = LOWORD(lParam);
37 yOrig = HIWORD(lParam);
38 SetCapture(hwnd);
39 break;
40 case WM_MOUSEMOVE:
41 if (resizing)
42 {
43 TCHAR sizeStr[100];
44 short xRel;
45 short yRel;
46 xRel = ((short)LOWORD(lParam) - xOrig) * 1000 / zoom;
47 yRel = ((short)HIWORD(lParam) - yOrig) * 1000 / zoom;
48 if (hwnd == hSizeboxLeftTop)
49 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes - yRel);
50 if (hwnd == hSizeboxCenterTop)
51 _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes - yRel);
52 if (hwnd == hSizeboxRightTop)
53 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes - yRel);
54 if (hwnd == hSizeboxLeftCenter)
55 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes);
56 if (hwnd == hSizeboxRightCenter)
57 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes);
58 if (hwnd == hSizeboxLeftBottom)
59 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes + yRel);
60 if (hwnd == hSizeboxCenterBottom)
61 _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes + yRel);
62 if (hwnd == hSizeboxRightBottom)
63 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes + yRel);
64 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
65 }
66 break;
67 case WM_LBUTTONUP:
68 if (resizing)
69 {
70 short xRel;
71 short yRel;
72 ReleaseCapture();
73 resizing = FALSE;
74 xRel = ((short)LOWORD(lParam) - xOrig) * 1000 / zoom;
75 yRel = ((short)HIWORD(lParam) - yOrig) * 1000 / zoom;
76 if (hwnd == hSizeboxLeftTop)
77 cropReversible(imgXRes - xRel, imgYRes - yRel, xRel, yRel);
78 if (hwnd == hSizeboxCenterTop)
79 cropReversible(imgXRes, imgYRes - yRel, 0, yRel);
80 if (hwnd == hSizeboxRightTop)
81 cropReversible(imgXRes + xRel, imgYRes - yRel, 0, yRel);
82 if (hwnd == hSizeboxLeftCenter)
83 cropReversible(imgXRes - xRel, imgYRes, xRel, 0);
84 if (hwnd == hSizeboxRightCenter)
85 cropReversible(imgXRes + xRel, imgYRes, 0, 0);
86 if (hwnd == hSizeboxLeftBottom)
87 cropReversible(imgXRes - xRel, imgYRes + yRel, xRel, 0);
88 if (hwnd == hSizeboxCenterBottom)
89 cropReversible(imgXRes, imgYRes + yRel, 0, 0);
90 if (hwnd == hSizeboxRightBottom)
91 cropReversible(imgXRes + xRel, imgYRes + yRel, 0, 0);
92 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T(""));
93 }
94 break;
95
96 default:
97 return DefWindowProc(hwnd, message, wParam, lParam);
98 }
99
100 return 0;
101 }