ReactOS 0.4.15-dev-5865-g640e228
imgarea.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint/imgarea.cpp
5 * PURPOSE: Window procedure of the main window and all children apart from
6 * hPalWin, hToolSettings and hSelection
7 * PROGRAMMERS: Benedikt Freisen
8 * Katayama Hirofumi MZ
9 */
10
11#include "precomp.h"
12
13/* FUNCTIONS ********************************************************/
14
16{
22
23 return 0;
24}
25
26void CImgAreaWindow::drawZoomFrame(int mouseX, int mouseY)
27{
28 HDC hdc;
29 HPEN oldPen;
30 HBRUSH oldBrush;
31 LOGBRUSH logbrush;
32 int rop;
33
34 RECT clientRectCanvas;
35 RECT clientRectImageArea;
36 int x, y, w, h;
37 canvasWindow.GetClientRect(&clientRectCanvas);
38 GetClientRect(&clientRectImageArea);
39 w = clientRectImageArea.right * 2;
40 h = clientRectImageArea.bottom * 2;
41 if (!w || !h)
42 {
43 return;
44 }
45 w = clientRectImageArea.right * clientRectCanvas.right / w;
46 h = clientRectImageArea.bottom * clientRectCanvas.bottom / h;
47 x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2));
48 y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2));
49
50 hdc = GetDC();
51 oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 0, 0));
52 logbrush.lbStyle = BS_HOLLOW;
53 oldBrush = (HBRUSH) SelectObject(hdc, CreateBrushIndirect(&logbrush));
55 Rectangle(hdc, x, y, x + w, y + h);
56 SetROP2(hdc, rop);
57 DeleteObject(SelectObject(hdc, oldBrush));
60}
61
63{
64 if (!IsWindow())
65 return 0;
67 return 0;
68}
69
71{
72 HDC hdc = (HDC)wParam;
73
76 {
77 // Do clipping
79 RECT rcChild;
80 ::GetWindowRect(hChild, &rcChild);
81 ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rcChild, 2);
82 ExcludeClipRect(hdc, rcChild.left, rcChild.top, rcChild.right, rcChild.bottom);
83 }
84
85 return DefWindowProc(nMsg, wParam, lParam);
86}
87
89{
90 PAINTSTRUCT ps;
91 HDC hdc = BeginPaint(&ps);
92 int imgXRes = imageModel.GetWidth();
93 int imgYRes = imageModel.GetHeight();
94 StretchBlt(hdc, 0, 0, Zoomed(imgXRes), Zoomed(imgYRes), imageModel.GetDC(), 0, 0, imgXRes,
95 imgYRes, SRCCOPY);
96 if (showGrid && (toolsModel.GetZoom() >= 4000))
97 {
98 HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, 0x00a0a0a0));
99 int counter;
100 for(counter = 0; counter <= imgYRes; counter++)
101 {
103 LineTo(hdc, Zoomed(imgXRes), Zoomed(counter));
104 }
105 for(counter = 0; counter <= imgXRes; counter++)
106 {
108 LineTo(hdc, Zoomed(counter), Zoomed(imgYRes));
109 }
110 DeleteObject(SelectObject(hdc, oldPen));
111 }
112 EndPaint(&ps);
113 if (selectionWindow.IsWindow())
114 selectionWindow.Invalidate(FALSE);
115 if (miniature.IsWindow())
116 miniature.Invalidate(FALSE);
117 if (textEditWindow.IsWindow())
118 textEditWindow.Invalidate(FALSE);
119 return 0;
120}
121
123{
124 switch (toolsModel.GetActiveTool())
125 {
126 case TOOL_FILL:
128 break;
129 case TOOL_COLOR:
131 break;
132 case TOOL_ZOOM:
134 break;
135 case TOOL_PEN:
137 break;
138 case TOOL_AIRBRUSH:
140 break;
141 default:
143 }
144 return 0;
145}
146
148{
149 drawing = TRUE;
150 SetCapture();
153 Invalidate(FALSE);
154 return 0;
155}
156
158{
159 drawing = FALSE;
164 Invalidate(FALSE);
165 return 0;
166}
167
169{
170 drawing = TRUE;
171 SetCapture();
174 Invalidate(FALSE);
175 return 0;
176}
177
179{
180 drawing = FALSE;
185 Invalidate(FALSE);
186 return 0;
187}
188
190{
191 if (drawing)
192 {
193 drawing = FALSE;
196 Invalidate(FALSE);
198 }
200 return 0;
201}
202
204{
205 drawing = FALSE;
207 Invalidate(FALSE);
208}
209
211{
212 if (drawing)
214 return 0;
215}
216
218{
219 if (wParam == VK_ESCAPE)
220 {
221 if (GetCapture() == m_hWnd)
222 {
224 }
225 else
226 {
227 if (drawing || ToolBase::pointSP != 0 || selectionWindow.IsWindowVisible())
229 }
230 }
231 return 0;
232}
233
235{
236 if (drawing)
237 {
238 drawing = FALSE;
241 Invalidate(FALSE);
243 }
245 return 0;
246}
247
249{
253 {
254 TRACKMOUSEEVENT tme;
255
257 {
258 Invalidate(FALSE);
259 UpdateWindow();
261 }
262
263 tme.cbSize = sizeof(TRACKMOUSEEVENT);
264 tme.dwFlags = TME_LEAVE;
265 tme.hwndTrack = m_hWnd;
266 tme.dwHoverTime = 0;
267 TrackMouseEvent(&tme);
268
269 if (!drawing)
270 {
271 CString strCoord;
272 strCoord.Format(_T("%ld, %ld"), xNow, yNow);
274 }
275 }
276 if (drawing)
277 {
278 /* values displayed in statusbar */
279 LONG xRel = xNow - start.x;
280 LONG yRel = yNow - start.y;
281 /* freesel, rectsel and text tools always show numbers limited to fit into image area */
283 {
284 if (xRel < 0)
285 xRel = (xNow < 0) ? -start.x : xRel;
286 else if (xNow > imageModel.GetWidth())
287 xRel = imageModel.GetWidth() - start.x;
288 if (yRel < 0)
289 yRel = (yNow < 0) ? -start.y : yRel;
290 else if (yNow > imageModel.GetHeight())
291 yRel = imageModel.GetHeight() - start.y;
292 }
293 /* rectsel and shape tools always show non-negative numbers when drawing */
295 {
296 if (xRel < 0)
297 xRel = -xRel;
298 if (yRel < 0)
299 yRel = -yRel;
300 }
301 /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
302 switch(toolsModel.GetActiveTool())
303 {
304 case TOOL_RUBBER:
305 case TOOL_PEN:
306 case TOOL_BRUSH:
307 case TOOL_AIRBRUSH:
308 case TOOL_SHAPE:
309 {
310 CString strCoord;
311 strCoord.Format(_T("%ld, %ld"), xNow, yNow);
313 break;
314 }
315 default:
316 break;
317 }
318 if (wParam & MK_LBUTTON)
319 {
320 toolsModel.OnMouseMove(TRUE, xNow, yNow);
321 Invalidate(FALSE);
323 {
324 CString strSize;
326 yRel = xRel;
327 strSize.Format(_T("%ld x %ld"), xRel, yRel);
329 }
330 }
331 if (wParam & MK_RBUTTON)
332 {
333 toolsModel.OnMouseMove(FALSE, xNow, yNow);
334 Invalidate(FALSE);
336 {
337 CString strSize;
339 yRel = xRel;
340 strSize.Format(_T("%ld x %ld"), xRel, yRel);
342 }
343 }
344 }
345 return 0;
346}
347
349{
352 Invalidate(FALSE);
353 return 0;
354}
355
357{
359 return 0;
360}
361
363{
364 Invalidate(FALSE);
365 return 0;
366}
367
369{
370 return ::SendMessage(GetParent(), nMsg, wParam, lParam);
371}
372
374{
375 HDC hdc = (HDC)wParam;
378}
379
381{
383 drawing = FALSE;
384 Invalidate(FALSE);
385}
#define IDC_ZOOM
Definition: resource.h:16
static int UnZoomed(int xy)
Definition: common.h:42
static int Zoomed(int xy)
Definition: common.h:37
#define IDC_FILL
Definition: resource.h:21
#define IDC_PEN
Definition: resource.h:24
#define IDC_COLOR
Definition: resource.h:22
#define IDC_AIRBRUSH
Definition: resource.h:25
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:753
VOID Update(HWND hwndFrom)
Definition: canvas.cpp:59
LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:368
LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:15
void cancelDrawing()
Definition: imgarea.cpp:203
LRESULT OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:168
BOOL drawing
Definition: imgarea.h:20
HCURSOR m_hCurAirbrush
Definition: imgarea.h:53
HCURSOR m_hCurFill
Definition: imgarea.h:49
HCURSOR m_hCurColor
Definition: imgarea.h:50
LRESULT OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:373
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:147
void finishDrawing()
Definition: imgarea.cpp:380
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:248
LRESULT OnEraseBkGnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:70
LRESULT OnImageModelDimensionsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:356
HCURSOR m_hCurZoom
Definition: imgarea.h:51
LRESULT OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:234
LRESULT OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:157
LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:62
void drawZoomFrame(int mouseX, int mouseY)
Definition: imgarea.cpp:26
HCURSOR m_hCurPen
Definition: imgarea.h:52
LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:122
LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:217
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:88
LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:189
LRESULT OnImageModelImageChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:362
LRESULT OnMouseLeave(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:348
LRESULT OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:178
LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:210
int GetWidth() const
Definition: history.cpp:215
int GetHeight() const
Definition: history.cpp:220
HDC GetDC()
Definition: history.cpp:239
int GetZoom() const
Definition: toolsmodel.cpp:148
void resetTool()
Definition: toolsmodel.cpp:231
void OnFinishDraw()
Definition: toolsmodel.cpp:223
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y)
Definition: toolsmodel.cpp:199
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
Definition: toolsmodel.cpp:191
BOOL IsBackgroundTransparent() const
Definition: toolsmodel.cpp:135
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:76
void OnCancelDraw()
Definition: toolsmodel.cpp:215
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
Definition: toolsmodel.cpp:207
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLuint start
Definition: gl.h:1545
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
ToolsModel toolsModel
Definition: main.cpp:16
CMiniatureWindow miniature
Definition: main.cpp:49
CSelectionWindow selectionWindow
Definition: main.cpp:54
ImageModel imageModel
Definition: main.cpp:24
HINSTANCE hProgInstance
Definition: main.cpp:34
CCanvasWindow canvasWindow
Definition: main.cpp:53
BOOL showGrid
Definition: main.cpp:44
CTextEditWindow textEditWindow
Definition: main.cpp:56
HWND hStatusBar
Definition: main.cpp:27
if(dx< 0)
Definition: linetemp.h:194
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
static HTREEITEM hChild
Definition: treeview.c:381
#define min(a, b)
Definition: monoChain.cc:55
static int rop(int rop, int src, int dst)
Definition: nanoxwin.c:124
unsigned int UINT
Definition: ndis.h:50
long LONG
Definition: pedump.c:60
#define TME_LEAVE
Definition: commctrl.h:4981
struct tagTRACKMOUSEEVENT TRACKMOUSEEVENT
#define SB_SETTEXT
Definition: commctrl.h:1949
#define DefWindowProc
Definition: ros2win.h:31
static INT pointSP
Definition: toolsmodel.h:39
UINT lbStyle
Definition: wingdi.h:1747
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define max(a, b)
Definition: svc.c:63
@ TOOL_AIRBRUSH
Definition: toolsmodel.h:21
@ TOOL_COLOR
Definition: toolsmodel.h:17
@ TOOL_SHAPE
Definition: toolsmodel.h:26
@ TOOL_RUBBER
Definition: toolsmodel.h:15
@ TOOL_BRUSH
Definition: toolsmodel.h:20
@ TOOL_FILL
Definition: toolsmodel.h:16
@ TOOL_TEXT
Definition: toolsmodel.h:22
@ TOOL_PEN
Definition: toolsmodel.h:19
@ TOOL_LINE
Definition: toolsmodel.h:23
@ TOOL_FREESEL
Definition: toolsmodel.h:13
@ TOOL_ZOOM
Definition: toolsmodel.h:18
@ TOOL_RECTSEL
Definition: toolsmodel.h:14
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
HBRUSH WINAPI CreateBrushIndirect(_In_ const LOGBRUSH *plb)
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI ExcludeClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
#define TRANSPARENT
Definition: wingdi.h:950
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define SRCCOPY
Definition: wingdi.h:333
#define BS_HOLLOW
Definition: wingdi.h:1088
#define NULL_BRUSH
Definition: wingdi.h:901
#define R2_NOT
Definition: wingdi.h:347
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
int WINAPI SetROP2(_In_ HDC, _In_ int)
Definition: dc.c:1107
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
#define PS_SOLID
Definition: wingdi.h:586
HWND WINAPI SetCapture(_In_ HWND hWnd)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define MK_RBUTTON
Definition: winuser.h:2358
BOOL WINAPI IsWindow(_In_opt_ HWND)
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
HWND WINAPI GetCapture(void)
Definition: message.c:2881
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define IDC_CROSS
Definition: winuser.h:685
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define LoadIcon
Definition: winuser.h:5803
BOOL WINAPI UpdateWindow(_In_ HWND)
#define SendMessage
Definition: winuser.h:5833
#define LoadCursor
Definition: winuser.h:5802
HDC WINAPI GetDC(_In_opt_ HWND)
HWND WINAPI GetParent(_In_ HWND)
#define MK_LBUTTON
Definition: winuser.h:2357
#define VK_SHIFT
Definition: winuser.h:2192
SHORT WINAPI GetAsyncKeyState(_In_ int)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define VK_ESCAPE
Definition: winuser.h:2204
BOOL WINAPI IsWindowVisible(_In_ HWND)
#define MAKEINTRESOURCE
Definition: winuser.h:591
const CHAR * LPCTSTR
Definition: xmlstorage.h:193