- Revert 44301
[reactos.git] / base / applications / paint / selection.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/paint/selection.c
5 * PURPOSE: Window procedure of the selection window
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include <windows.h>
12 #include "globalvar.h"
13 #include "drawing.h"
14 #include "history.h"
15 #include "mouse.h"
16
17 /* FUNCTIONS ********************************************************/
18
19 BOOL moving = FALSE;
20 short xPos;
21 short yPos;
22
23 LRESULT CALLBACK
24 SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
25 {
26 switch (message)
27 {
28 case WM_PAINT:
29 {
30 if (!moving)
31 {
32 HDC hDC = GetDC(hwnd);
33 DefWindowProc(hwnd, message, wParam, lParam);
34 SelectionFrame(hDC, 1, 1, rectSel_dest[2] * zoom / 1000 + 5,
35 rectSel_dest[3] * zoom / 1000 + 5);
36 ReleaseDC(hwnd, hDC);
37 }
38 break;
39 }
40 case WM_LBUTTONDOWN:
41 xPos = LOWORD(lParam);
42 yPos = HIWORD(lParam);
43 SetCapture(hwnd);
44 moving = TRUE;
45 break;
46 case WM_MOUSEMOVE:
47 if (moving)
48 {
49 resetToU1();
50 rectSel_dest[0] += (short)LOWORD(lParam) - xPos;
51 rectSel_dest[1] += (short)HIWORD(lParam) - yPos;
52
53 Rect(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[0] + rectSel_src[2],
54 rectSel_src[1] + rectSel_src[3], bgColor, bgColor, 0, TRUE);
55 if (transpBg == 0)
56 BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
57 hSelDC, 0, 0, SRCCOPY);
58 else
59 BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
60 hSelDC, 0, 0, SRCAND);
61 //TransparentBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
62 // hSelDC, 0, 0, rectSel_dest[2], rectSel_dest[3], bgColor);
63 SendMessage(hImageArea, WM_PAINT, 0, 0);
64 xPos = LOWORD(lParam);
65 yPos = HIWORD(lParam);
66 //SendMessage(hwnd, WM_PAINT, 0, 0);
67 }
68 break;
69 case WM_LBUTTONUP:
70 if (moving)
71 {
72 moving = FALSE;
73 ReleaseCapture();
74 placeSelWin();
75 ShowWindow(hSelection, SW_HIDE);
76 ShowWindow(hSelection, SW_SHOW);
77 }
78 break;
79 default:
80 return DefWindowProc(hwnd, message, wParam, lParam);
81 }
82
83 return 0;
84 }