ReactOS  0.4.15-dev-5142-g967f5b9
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 /* INCLUDES *********************************************************/
12 
13 #include "precomp.h"
14 
15 /* FUNCTIONS ********************************************************/
16 
17 void
19 {
20  selectionWindow.ShowWindow(SW_HIDE);
21 
22  int zoomedWidth = Zoomed(imageModel.GetWidth());
23  int zoomedHeight = Zoomed(imageModel.GetHeight());
24  imageArea.MoveWindow(GRIP_SIZE, GRIP_SIZE, zoomedWidth, zoomedHeight, FALSE);
25 
26  scrollboxWindow.Invalidate(TRUE);
28 
29  scrollboxWindow.SetScrollPos(SB_HORZ, 0, TRUE);
30  scrollboxWindow.SetScrollPos(SB_VERT, 0, TRUE);
31 }
32 
33 void CImgAreaWindow::drawZoomFrame(int mouseX, int mouseY)
34 {
35  HDC hdc;
36  HPEN oldPen;
37  HBRUSH oldBrush;
38  LOGBRUSH logbrush;
39  int rop;
40 
41  RECT clientRectScrollbox;
42  RECT clientRectImageArea;
43  int x, y, w, h;
44  scrollboxWindow.GetClientRect(&clientRectScrollbox);
45  GetClientRect(&clientRectImageArea);
46  w = clientRectImageArea.right * 2;
47  h = clientRectImageArea.bottom * 2;
48  if (!w || !h)
49  {
50  return;
51  }
52  w = clientRectImageArea.right * clientRectScrollbox.right / w;
53  h = clientRectImageArea.bottom * clientRectScrollbox.bottom / h;
54  x = max(0, min(clientRectImageArea.right - w, mouseX - w / 2));
55  y = max(0, min(clientRectImageArea.bottom - h, mouseY - h / 2));
56 
57  hdc = GetDC();
58  oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 0, 0));
59  logbrush.lbStyle = BS_HOLLOW;
60  oldBrush = (HBRUSH) SelectObject(hdc, CreateBrushIndirect(&logbrush));
61  rop = SetROP2(hdc, R2_NOT);
62  Rectangle(hdc, x, y, x + w, y + h);
63  SetROP2(hdc, rop);
64  DeleteObject(SelectObject(hdc, oldBrush));
65  DeleteObject(SelectObject(hdc, oldPen));
66  ReleaseDC(hdc);
67 }
68 
70 {
71  if (!IsWindow() || !sizeboxLeftTop.IsWindow())
72  return 0;
73  int imgXRes = imageModel.GetWidth();
74  int imgYRes = imageModel.GetHeight();
75  sizeboxLeftTop.MoveWindow(
76  0,
77  0, GRIP_SIZE, GRIP_SIZE, TRUE);
78  sizeboxCenterTop.MoveWindow(
79  GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2,
80  0, GRIP_SIZE, GRIP_SIZE, TRUE);
81  sizeboxRightTop.MoveWindow(
82  GRIP_SIZE + Zoomed(imgXRes),
83  0, GRIP_SIZE, GRIP_SIZE, TRUE);
84  sizeboxLeftCenter.MoveWindow(
85  0,
86  GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2,
88  sizeboxRightCenter.MoveWindow(
89  GRIP_SIZE + Zoomed(imgXRes),
90  GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2,
92  sizeboxLeftBottom.MoveWindow(
93  0,
94  GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
95  sizeboxCenterBottom.MoveWindow(
96  GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2,
97  GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
98  sizeboxRightBottom.MoveWindow(
99  GRIP_SIZE + Zoomed(imgXRes),
100  GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
101  UpdateScrollbox();
102  return 0;
103 }
104 
106 {
107  HDC hdc = (HDC)wParam;
108 
111  {
112  // Do clipping
114  RECT rcChild;
115  ::GetWindowRect(hChild, &rcChild);
116  ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rcChild, 2);
117  ExcludeClipRect(hdc, rcChild.left, rcChild.top, rcChild.right, rcChild.bottom);
118  }
119 
120  return DefWindowProc(nMsg, wParam, lParam);
121 }
122 
124 {
125  PAINTSTRUCT ps;
126  HDC hdc = BeginPaint(&ps);
127  int imgXRes = imageModel.GetWidth();
128  int imgYRes = imageModel.GetHeight();
129  StretchBlt(hdc, 0, 0, Zoomed(imgXRes), Zoomed(imgYRes), imageModel.GetDC(), 0, 0, imgXRes,
130  imgYRes, SRCCOPY);
131  if (showGrid && (toolsModel.GetZoom() >= 4000))
132  {
133  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_SOLID, 1, 0x00a0a0a0));
134  int counter;
135  for(counter = 0; counter <= imgYRes; counter++)
136  {
137  MoveToEx(hdc, 0, Zoomed(counter), NULL);
138  LineTo(hdc, Zoomed(imgXRes), Zoomed(counter));
139  }
140  for(counter = 0; counter <= imgXRes; counter++)
141  {
142  MoveToEx(hdc, Zoomed(counter), 0, NULL);
143  LineTo(hdc, Zoomed(counter), Zoomed(imgYRes));
144  }
145  DeleteObject(SelectObject(hdc, oldPen));
146  }
147  EndPaint(&ps);
148  if (selectionWindow.IsWindow())
149  selectionWindow.Invalidate(FALSE);
150  if (miniature.IsWindow())
151  miniature.Invalidate(FALSE);
152  if (textEditWindow.IsWindow())
153  textEditWindow.Invalidate(FALSE);
154  return 0;
155 }
156 
158 {
159  switch (toolsModel.GetActiveTool())
160  {
161  case TOOL_FILL:
163  break;
164  case TOOL_COLOR:
166  break;
167  case TOOL_ZOOM:
169  break;
170  case TOOL_PEN:
172  break;
173  case TOOL_AIRBRUSH:
175  break;
176  default:
178  }
179  return 0;
180 }
181 
183 {
184  drawing = TRUE;
185  SetCapture();
188  Invalidate(FALSE);
189  return 0;
190 }
191 
193 {
194  drawing = FALSE;
195  ReleaseCapture();
199  Invalidate(FALSE);
200  return 0;
201 }
202 
204 {
205  drawing = TRUE;
206  SetCapture();
209  Invalidate(FALSE);
210  return 0;
211 }
212 
214 {
215  drawing = FALSE;
216  ReleaseCapture();
220  Invalidate(FALSE);
221  return 0;
222 }
223 
225 {
226  if (drawing)
227  {
228  drawing = FALSE;
231  Invalidate(FALSE);
233  }
234  ReleaseCapture();
235  return 0;
236 }
237 
239 {
240  drawing = FALSE;
242  Invalidate(FALSE);
243 }
244 
246 {
247  if (drawing)
248  cancelDrawing();
249  return 0;
250 }
251 
253 {
254  if (wParam == VK_ESCAPE)
255  {
256  if (GetCapture() == m_hWnd)
257  {
258  ReleaseCapture();
259  }
260  else
261  {
262  if (drawing || ToolBase::pointSP != 0 || selectionWindow.IsWindowVisible())
263  cancelDrawing();
264  }
265  }
266  return 0;
267 }
268 
270 {
271  if (drawing)
272  {
273  drawing = FALSE;
276  Invalidate(FALSE);
278  }
279  ReleaseCapture();
280  return 0;
281 }
282 
284 {
285  LONG xNow = UnZoomed(GET_X_LPARAM(lParam));
286  LONG yNow = UnZoomed(GET_Y_LPARAM(lParam));
288  {
289  TRACKMOUSEEVENT tme;
290 
292  {
293  Invalidate(FALSE);
294  UpdateWindow();
296  }
297 
298  tme.cbSize = sizeof(TRACKMOUSEEVENT);
299  tme.dwFlags = TME_LEAVE;
300  tme.hwndTrack = m_hWnd;
301  tme.dwHoverTime = 0;
302  TrackMouseEvent(&tme);
303 
304  if (!drawing)
305  {
306  CString strCoord;
307  strCoord.Format(_T("%ld, %ld"), xNow, yNow);
308  SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord);
309  }
310  }
311  if (drawing)
312  {
313  /* values displayed in statusbar */
314  LONG xRel = xNow - start.x;
315  LONG yRel = yNow - start.y;
316  /* freesel, rectsel and text tools always show numbers limited to fit into image area */
318  {
319  if (xRel < 0)
320  xRel = (xNow < 0) ? -start.x : xRel;
321  else if (xNow > imageModel.GetWidth())
322  xRel = imageModel.GetWidth() - start.x;
323  if (yRel < 0)
324  yRel = (yNow < 0) ? -start.y : yRel;
325  else if (yNow > imageModel.GetHeight())
326  yRel = imageModel.GetHeight() - start.y;
327  }
328  /* rectsel and shape tools always show non-negative numbers when drawing */
330  {
331  if (xRel < 0)
332  xRel = -xRel;
333  if (yRel < 0)
334  yRel = -yRel;
335  }
336  /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
337  switch(toolsModel.GetActiveTool())
338  {
339  case TOOL_RUBBER:
340  case TOOL_PEN:
341  case TOOL_BRUSH:
342  case TOOL_AIRBRUSH:
343  case TOOL_SHAPE:
344  {
345  CString strCoord;
346  strCoord.Format(_T("%ld, %ld"), xNow, yNow);
347  SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord);
348  break;
349  }
350  default:
351  break;
352  }
353  if (wParam & MK_LBUTTON)
354  {
355  toolsModel.OnMouseMove(TRUE, xNow, yNow);
356  Invalidate(FALSE);
358  {
359  CString strSize;
361  yRel = xRel;
362  strSize.Format(_T("%ld x %ld"), xRel, yRel);
363  SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
364  }
365  }
366  if (wParam & MK_RBUTTON)
367  {
368  toolsModel.OnMouseMove(FALSE, xNow, yNow);
369  Invalidate(FALSE);
371  {
372  CString strSize;
374  yRel = xRel;
375  strSize.Format(_T("%ld x %ld"), xRel, yRel);
376  SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize);
377  }
378  }
379  }
380  return 0;
381 }
382 
384 {
387  Invalidate(FALSE);
388  return 0;
389 }
390 
392 {
394  return 0;
395 }
396 
398 {
399  Invalidate(FALSE);
400  return 0;
401 }
402 
404 {
406 }
407 
409 {
410  HDC hdc = (HDC)wParam;
413 }
414 
416 {
418  drawing = FALSE;
419  Invalidate(FALSE);
420 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
static int Zoomed(int xy)
Definition: common.h:37
HCURSOR hCurFill
Definition: main.cpp:42
int MapWindowPoints(HWND hWndTo, LPPOINT lpPoint, UINT nCount) const
Definition: atlwin.h:984
ToolsModel toolsModel
Definition: main.cpp:18
#define max(a, b)
Definition: svc.c:63
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
BOOL MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint=TRUE)
Definition: atlwin.h:1020
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
void resetTool()
Definition: toolsmodel.cpp:231
#define R2_NOT
Definition: wingdi.h:347
#define MK_LBUTTON
Definition: winuser.h:2357
UINT lbStyle
Definition: wingdi.h:1747
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define SB_VERT
Definition: winuser.h:553
static HTREEITEM hChild
Definition: treeview.c:381
#define TRUE
Definition: types.h:120
BOOL showGrid
Definition: main.cpp:60
#define SW_HIDE
Definition: winuser.h:762
void OnCancelDraw()
Definition: toolsmodel.cpp:215
#define NULL_BRUSH
Definition: wingdi.h:901
#define SB_HORZ
Definition: winuser.h:552
static HDC
Definition: imagelist.c:92
BOOL IsWindow() const
Definition: atlwin.h:941
void drawZoomFrame(int mouseX, int mouseY)
Definition: imgarea.cpp:33
#define GET_X_LPARAM(lp)
Definition: windowsx.h:274
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
CSizeboxWindow sizeboxRightCenter
Definition: main.cpp:77
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:753
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
LRESULT OnEraseBkGnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:105
UINT_PTR WPARAM
Definition: windef.h:207
void EndPaint(LPPAINTSTRUCT lpPaint)
Definition: atlwin.h:523
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define VK_ESCAPE
Definition: winuser.h:2204
LONG right
Definition: windef.h:308
int32_t INT
Definition: typedefs.h:58
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)
WPARAM wParam
Definition: combotst.c:138
void OnButtonDown(BOOL bLeftButton, LONG x, LONG y, BOOL bDoubleClick)
Definition: toolsmodel.cpp:191
LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: atlwin.h:1606
void OnMouseMove(BOOL bLeftButton, LONG x, LONG y)
Definition: toolsmodel.cpp:199
LRESULT OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:203
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
HCURSOR hCurPen
Definition: main.cpp:45
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
CImgAreaWindow imageArea
Definition: main.cpp:72
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
#define PS_SOLID
Definition: wingdi.h:586
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
CSizeboxWindow sizeboxCenterTop
Definition: main.cpp:74
CSizeboxWindow sizeboxRightTop
Definition: main.cpp:75
LRESULT OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:192
CSizeboxWindow sizeboxCenterBottom
Definition: main.cpp:79
#define FALSE
Definition: types.h:117
LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:69
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
int WINAPI SetROP2(_In_ HDC, _In_ int)
Definition: dc.c:1107
LRESULT OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:213
HCURSOR hCurAirbrush
Definition: main.cpp:46
HDC GetDC()
Definition: history.cpp:239
static int rop(int rop, int src, int dst)
Definition: nanoxwin.c:124
BOOL GetClientRect(LPRECT lpRect) const
Definition: atlwin.h:535
HWND WINAPI GetCapture(void)
Definition: message.c:2881
void OnFinishDraw()
Definition: toolsmodel.cpp:223
#define TRANSPARENT
Definition: wingdi.h:950
BOOL GetWindowRect(LPRECT lpRect) const
Definition: atlwin.h:810
#define VK_SHIFT
Definition: winuser.h:2192
LRESULT OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:408
CMiniatureWindow miniature
Definition: main.cpp:65
LONG_PTR LPARAM
Definition: windef.h:208
CSizeboxWindow sizeboxRightBottom
Definition: main.cpp:80
GLuint counter
Definition: glext.h:11116
HCURSOR hCurZoom
Definition: main.cpp:44
#define MK_RBUTTON
Definition: winuser.h:2358
int GetWidth() const
Definition: history.cpp:215
static INT pointSP
Definition: toolsmodel.h:39
#define _T(x)
Definition: vfdio.h:22
LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:224
void OnButtonUp(BOOL bLeftButton, LONG x, LONG y)
Definition: toolsmodel.cpp:207
void finishDrawing()
Definition: imgarea.cpp:415
HDC BeginPaint(LPPAINTSTRUCT lpPaint)
Definition: atlwin.h:297
BOOL UpdateWindow()
Definition: atlwin.h:1339
void updateCanvasAndScrollbars()
Definition: imgarea.cpp:18
HWND hStatusBar
Definition: main.cpp:35
#define BS_HOLLOW
Definition: wingdi.h:1088
int GetZoom() const
Definition: toolsmodel.cpp:148
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:76
#define GRIP_SIZE
Definition: common.h:13
struct tagTRACKMOUSEEVENT TRACKMOUSEEVENT
HDC hdc
Definition: main.c:9
#define SB_SETTEXT
Definition: commctrl.h:1949
CSizeboxWindow sizeboxLeftCenter
Definition: main.cpp:76
SHORT WINAPI GetAsyncKeyState(_In_ int)
ImageModel imageModel
Definition: main.cpp:32
HWND m_hWnd
Definition: atlwin.h:267
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:182
#define LoadCursor
Definition: winuser.h:5802
HBRUSH WINAPI CreateBrushIndirect(_In_ const LOGBRUSH *plb)
LRESULT OnImageModelImageChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:397
int ReleaseDC(HDC hDC)
Definition: atlwin.h:1068
#define IDC_CROSS
Definition: winuser.h:685
CSizeboxWindow sizeboxLeftBottom
Definition: main.cpp:78
int GetHeight() const
Definition: history.cpp:220
LRESULT OnImageModelDimensionsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:391
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
int WINAPI ExcludeClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
GLuint start
Definition: gl.h:1545
#define TME_LEAVE
Definition: commctrl.h:4981
LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:157
LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:252
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
LRESULT OnMouseLeave(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:383
BOOL drawing
Definition: imgarea.h:20
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:275
CScrollboxWindow scrollboxWindow
Definition: main.cpp:69
void UpdateScrollbox()
Definition: scrollbox.cpp:53
void cancelDrawing()
Definition: imgarea.cpp:238
BOOL Invalidate(BOOL bErase=TRUE)
Definition: atlwin.h:890
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:123
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
CSizeboxWindow sizeboxLeftTop
Definition: main.cpp:73
#define SendMessage
Definition: winuser.h:5833
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:283
LRESULT OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:269
LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:403
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1110
LONG bottom
Definition: windef.h:309
CWindow GetParent() const
Definition: atlwin.h:694
CTextEditWindow textEditWindow
Definition: main.cpp:81
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
HCURSOR hCurColor
Definition: main.cpp:43
HDC GetDC()
Definition: atlwin.h:541
#define SRCCOPY
Definition: wingdi.h:333
HWND SetCapture()
Definition: atlwin.h:1162
BOOL IsWindowVisible() const
Definition: atlwin.h:952
CSelectionWindow selectionWindow
Definition: main.cpp:71
BOOL IsBackgroundTransparent() const
Definition: toolsmodel.cpp:135
LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: imgarea.cpp:245
static int UnZoomed(int xy)
Definition: common.h:42