[NTOS:IO]
[reactos.git] / reactos / 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 #include "sizebox.h"
13
14 /* FUNCTIONS ********************************************************/
15
16 BOOL resizing = FALSE;
17 short xOrig;
18 short yOrig;
19
20 void
21 RegisterWclSizebox()
22 {
23 WNDCLASSEX wclSizebox;
24 /* initializing and registering the window class for the size boxes */
25 wclSizebox.hInstance = hProgInstance;
26 wclSizebox.lpszClassName = _T("Sizebox");
27 wclSizebox.lpfnWndProc = SizeboxWinProc;
28 wclSizebox.style = CS_DBLCLKS;
29 wclSizebox.cbSize = sizeof(WNDCLASSEX);
30 wclSizebox.hIcon = NULL;
31 wclSizebox.hIconSm = NULL;
32 wclSizebox.hCursor = LoadCursor(NULL, IDC_ARROW);
33 wclSizebox.lpszMenuName = NULL;
34 wclSizebox.cbClsExtra = 0;
35 wclSizebox.cbWndExtra = 0;
36 wclSizebox.hbrBackground = GetSysColorBrush(COLOR_HIGHLIGHT);
37 RegisterClassEx (&wclSizebox);
38 }
39
40 LRESULT CALLBACK
41 SizeboxWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
42 {
43 switch (message)
44 {
45 case WM_SETCURSOR:
46 if ((hwnd == hSizeboxLeftTop) || (hwnd == hSizeboxRightBottom))
47 SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
48 if ((hwnd == hSizeboxLeftBottom) || (hwnd == hSizeboxRightTop))
49 SetCursor(LoadCursor(NULL, IDC_SIZENESW));
50 if ((hwnd == hSizeboxLeftCenter) || (hwnd == hSizeboxRightCenter))
51 SetCursor(LoadCursor(NULL, IDC_SIZEWE));
52 if ((hwnd == hSizeboxCenterTop) || (hwnd == hSizeboxCenterBottom))
53 SetCursor(LoadCursor(NULL, IDC_SIZENS));
54 break;
55 case WM_LBUTTONDOWN:
56 resizing = TRUE;
57 xOrig = GET_X_LPARAM(lParam);
58 yOrig = GET_Y_LPARAM(lParam);
59 SetCapture(hwnd);
60 break;
61 case WM_MOUSEMOVE:
62 if (resizing)
63 {
64 TCHAR sizeStr[100];
65 short xRel;
66 short yRel;
67 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / zoom;
68 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / zoom;
69 if (hwnd == hSizeboxLeftTop)
70 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes - yRel);
71 if (hwnd == hSizeboxCenterTop)
72 _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes - yRel);
73 if (hwnd == hSizeboxRightTop)
74 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes - yRel);
75 if (hwnd == hSizeboxLeftCenter)
76 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes);
77 if (hwnd == hSizeboxRightCenter)
78 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes);
79 if (hwnd == hSizeboxLeftBottom)
80 _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes + yRel);
81 if (hwnd == hSizeboxCenterBottom)
82 _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes + yRel);
83 if (hwnd == hSizeboxRightBottom)
84 _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes + yRel);
85 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
86 }
87 break;
88 case WM_LBUTTONUP:
89 if (resizing)
90 {
91 short xRel;
92 short yRel;
93 ReleaseCapture();
94 resizing = FALSE;
95 xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / zoom;
96 yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / zoom;
97 if (hwnd == hSizeboxLeftTop)
98 cropReversible(imgXRes - xRel, imgYRes - yRel, xRel, yRel);
99 if (hwnd == hSizeboxCenterTop)
100 cropReversible(imgXRes, imgYRes - yRel, 0, yRel);
101 if (hwnd == hSizeboxRightTop)
102 cropReversible(imgXRes + xRel, imgYRes - yRel, 0, yRel);
103 if (hwnd == hSizeboxLeftCenter)
104 cropReversible(imgXRes - xRel, imgYRes, xRel, 0);
105 if (hwnd == hSizeboxRightCenter)
106 cropReversible(imgXRes + xRel, imgYRes, 0, 0);
107 if (hwnd == hSizeboxLeftBottom)
108 cropReversible(imgXRes - xRel, imgYRes + yRel, xRel, 0);
109 if (hwnd == hSizeboxCenterBottom)
110 cropReversible(imgXRes, imgYRes + yRel, 0, 0);
111 if (hwnd == hSizeboxRightBottom)
112 cropReversible(imgXRes + xRel, imgYRes + yRel, 0, 0);
113 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T(""));
114 }
115 break;
116
117 default:
118 return DefWindowProc(hwnd, message, wParam, lParam);
119 }
120
121 return 0;
122 }