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