2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/paint/winproc.c
5 * PURPOSE: Window procedure of the main window and all children apart from
6 * hPalWin, hToolSettings and hSelection
7 * PROGRAMMERS: Benedikt Freisen
10 /* INCLUDES *********************************************************/
14 //#include <htmlhelp.h>
17 #include "definitions.h"
18 #include "globalvar.h"
26 /* FUNCTIONS ********************************************************/
31 ShowWindow(hSelection
, SW_HIDE
);
33 pointSP
= 0; // resets the point-buffer of the polygon and bezier functions
34 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
35 ShowWindow(hTrackbarZoom
, (tool
== 6) ? SW_SHOW
: SW_HIDE
);
39 updateCanvasAndScrollbars()
41 ShowWindow(hSelection
, SW_HIDE
);
42 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
43 InvalidateRect(hScrollbox
, NULL
, TRUE
);
44 InvalidateRect(hImageArea
, NULL
, FALSE
);
46 SetScrollPos(hScrollbox
, SB_HORZ
, 0, TRUE
);
47 SetScrollPos(hScrollbox
, SB_VERT
, 0, TRUE
);
51 zoomTo(int newZoom
, int mouseX
, int mouseY
)
54 int tempZoom
= newZoom
;
56 long clientRectScrollbox
[4];
57 long clientRectImageArea
[4];
59 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
60 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
61 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * newZoom
/ zoom
);
62 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * newZoom
/ zoom
);
63 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2)) * newZoom
/ zoom
;
64 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2)) * newZoom
/ zoom
;
68 ShowWindow(hSelection
, SW_HIDE
);
69 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
70 InvalidateRect(hScrollbox
, NULL
, TRUE
);
71 InvalidateRect(hImageArea
, NULL
, FALSE
);
73 SendMessage(hScrollbox
, WM_HSCROLL
, SB_THUMBPOSITION
| (x
<< 16), 0);
74 SendMessage(hScrollbox
, WM_VSCROLL
, SB_THUMBPOSITION
| (y
<< 16), 0);
76 while (tempZoom
> 125)
79 tempZoom
= tempZoom
>> 1;
81 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) tbPos
);
85 drawZoomFrame(int mouseX
, int mouseY
)
93 long clientRectScrollbox
[4];
94 long clientRectImageArea
[4];
96 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
97 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
98 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * 2);
99 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * 2);
100 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2));
101 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2));
103 hdc
= GetDC(hImageArea
);
104 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, 0));
105 logbrush
.lbStyle
= BS_HOLLOW
;
106 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
107 rop
= SetROP2(hdc
, R2_NOT
);
108 Rectangle(hdc
, x
, y
, x
+ w
, y
+ h
);
110 DeleteObject(SelectObject(hdc
, oldBrush
));
111 DeleteObject(SelectObject(hdc
, oldPen
));
112 ReleaseDC(hImageArea
, hdc
);
116 alignChildrenToMainWindow()
120 GetClientRect(hMainWnd
, &clientRect
);
122 if (IsWindowVisible(hToolBoxContainer
))
125 w
= clientRect
.right
- 56;
130 w
= clientRect
.right
;
132 if (IsWindowVisible(hPalWin
))
135 h
= clientRect
.bottom
- 49;
140 h
= clientRect
.bottom
- 3;
143 MoveWindow(hScrollbox
, x
, y
, w
, IsWindowVisible(hStatusBar
) ? h
- 23 : h
, TRUE
);
144 MoveWindow(hPalWin
, x
, 9, 255, 32, TRUE
);
150 WindowProcedure(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
152 switch (message
) /* handle the messages */
160 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
164 if (hwnd
== hwndMiniature
)
166 ShowWindow(hwndMiniature
, SW_HIDE
);
167 showMiniature
= FALSE
;
172 TCHAR programname
[20];
173 TCHAR saveprompttext
[100];
175 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
176 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
177 _stprintf(temptext
, saveprompttext
, filename
);
178 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
184 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
195 case WM_INITMENUPOPUP
:
201 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
202 MF_ENABLED
| MF_BYCOMMAND
);
203 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
204 MF_ENABLED
| MF_BYCOMMAND
);
205 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
206 MF_ENABLED
| MF_BYCOMMAND
);
210 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
211 MF_GRAYED
| MF_BYCOMMAND
);
212 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
213 MF_GRAYED
| MF_BYCOMMAND
);
214 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
215 MF_GRAYED
| MF_BYCOMMAND
);
219 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
,
220 (undoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
221 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
,
222 (redoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
223 if (IsWindowVisible(hSelection
))
225 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_ENABLED
| MF_BYCOMMAND
);
226 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_ENABLED
| MF_BYCOMMAND
);
227 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
228 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
229 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_ENABLED
| MF_BYCOMMAND
);
233 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_GRAYED
| MF_BYCOMMAND
);
234 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_GRAYED
| MF_BYCOMMAND
);
235 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
236 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
237 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_GRAYED
| MF_BYCOMMAND
);
239 OpenClipboard(hMainWnd
);
240 if (GetClipboardData(CF_BITMAP
) != NULL
)
241 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_ENABLED
| MF_BYCOMMAND
);
243 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_GRAYED
| MF_BYCOMMAND
);
247 if (IsWindowVisible(hSelection
))
248 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_ENABLED
| MF_BYCOMMAND
);
250 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_GRAYED
| MF_BYCOMMAND
);
251 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, (transpBg
== 0) ?
252 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
255 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWTOOLBOX
,
256 IsWindowVisible(hToolBoxContainer
) ?
257 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
258 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWCOLORPALETTE
,
259 IsWindowVisible(hPalWin
) ?
260 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
261 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
,
262 IsWindowVisible(hStatusBar
) ?
263 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
265 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
,
266 showGrid
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
267 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
,
268 showMiniature
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
270 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
,
271 (zoom
== 125) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
272 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
,
273 (zoom
== 250) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
274 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
,
275 (zoom
== 500) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
276 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
,
277 (zoom
== 1000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
278 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
,
279 (zoom
== 2000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
280 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
,
281 (zoom
== 4000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
282 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
,
283 (zoom
== 8000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
288 if (hwnd
== hMainWnd
)
290 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
291 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
292 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (LPARAM
)&test
);
293 alignChildrenToMainWindow();
295 if (hwnd
== hImageArea
)
297 MoveWindow(hSizeboxLeftTop
,
300 MoveWindow(hSizeboxCenterTop
,
301 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
303 MoveWindow(hSizeboxRightTop
,
304 imgXRes
* zoom
/ 1000 + 3,
306 MoveWindow(hSizeboxLeftCenter
,
308 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
309 MoveWindow(hSizeboxRightCenter
,
310 imgXRes
* zoom
/ 1000 + 3,
311 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
312 MoveWindow(hSizeboxLeftBottom
,
314 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
315 MoveWindow(hSizeboxCenterBottom
,
316 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
317 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
318 MoveWindow(hSizeboxRightBottom
,
319 imgXRes
* zoom
/ 1000 + 3,
320 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
322 if ((hwnd
== hImageArea
) || (hwnd
== hScrollbox
))
324 long clientRectScrollbox
[4];
325 long clientRectImageArea
[4];
327 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
328 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
329 si
.cbSize
= sizeof(SCROLLINFO
);
330 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
331 si
.nMax
= clientRectImageArea
[2] + 6 - 1;
333 si
.nPage
= clientRectScrollbox
[2];
334 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
335 GetClientRect(hScrollbox
, (LPRECT
) clientRectScrollbox
);
336 si
.nMax
= clientRectImageArea
[3] + 6 - 1;
337 si
.nPage
= clientRectScrollbox
[3];
338 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
339 MoveWindow(hScrlClient
,
340 -GetScrollPos(hScrollbox
, SB_HORZ
), -GetScrollPos(hScrollbox
, SB_VERT
),
341 max(clientRectImageArea
[2] + 6, clientRectScrollbox
[2]),
342 max(clientRectImageArea
[3] + 6, clientRectScrollbox
[3]), TRUE
);
347 if (hwnd
== hScrollbox
)
350 si
.cbSize
= sizeof(SCROLLINFO
);
352 GetScrollInfo(hScrollbox
, SB_HORZ
, &si
);
353 switch (LOWORD(wParam
))
356 case SB_THUMBPOSITION
:
357 si
.nPos
= HIWORD(wParam
);
372 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
373 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
374 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
375 imgYRes
* zoom
/ 1000 + 6, TRUE
);
380 if (hwnd
== hScrollbox
)
383 si
.cbSize
= sizeof(SCROLLINFO
);
385 GetScrollInfo(hScrollbox
, SB_VERT
, &si
);
386 switch (LOWORD(wParam
))
389 case SB_THUMBPOSITION
:
390 si
.nPos
= HIWORD(wParam
);
405 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
406 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
407 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
408 imgYRes
* zoom
/ 1000 + 6, TRUE
);
412 case WM_GETMINMAXINFO
:
413 if (hwnd
== hMainWnd
)
415 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
416 (*mm
).ptMinTrackSize
.x
= 330;
417 (*mm
).ptMinTrackSize
.y
= 430;
422 DefWindowProc(hwnd
, message
, wParam
, lParam
);
423 if (hwnd
== hImageArea
)
425 HDC hdc
= GetDC(hImageArea
);
426 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
428 if (showGrid
&& (zoom
>= 4000))
430 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
432 for(counter
= 0; counter
<= imgYRes
; counter
++)
434 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
435 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
437 for(counter
= 0; counter
<= imgXRes
; counter
++)
439 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
440 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
442 DeleteObject(SelectObject(hdc
, oldPen
));
444 ReleaseDC(hImageArea
, hdc
);
445 SendMessage(hSelection
, WM_PAINT
, 0, 0);
446 SendMessage(hwndMiniature
, WM_PAINT
, 0, 0);
448 else if (hwnd
== hwndMiniature
)
452 GetClientRect(hwndMiniature
, (LPRECT
) &mclient
);
453 hdc
= GetDC(hwndMiniature
);
454 BitBlt(hdc
, 0, 0, imgXRes
, imgYRes
, hDrawingDC
, 0, 0, SRCCOPY
);
455 ReleaseDC(hwndMiniature
, hdc
);
459 // mouse events used for drawing
462 if (hwnd
== hImageArea
)
470 SetCursor(hCurColor
);
479 SetCursor(hCurAirbrush
);
482 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
486 DefWindowProc(hwnd
, message
, wParam
, lParam
);
490 if (hwnd
== hImageArea
)
492 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
494 SetCapture(hImageArea
);
496 startPaintingL(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
,
501 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
504 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
505 if ((activeTool
== TOOL_ZOOM
) && (zoom
< 8000))
506 zoomTo(zoom
* 2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
511 if (hwnd
== hImageArea
)
513 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
515 SetCapture(hImageArea
);
517 startPaintingR(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
,
522 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
525 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
526 if ((activeTool
== TOOL_ZOOM
) && (zoom
> 125))
527 zoomTo(zoom
/ 2, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
532 if ((hwnd
== hImageArea
) && drawing
)
536 endPaintingL(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
, fgColor
,
538 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
539 if (activeTool
== TOOL_COLOR
)
542 GetPixel(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
);
543 if (tempColor
!= CLR_INVALID
)
545 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
547 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
552 if ((hwnd
== hImageArea
) && drawing
)
556 endPaintingR(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
, fgColor
,
558 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
559 if (activeTool
== TOOL_COLOR
)
562 GetPixel(hDrawingDC
, LOWORD(lParam
) * 1000 / zoom
, HIWORD(lParam
) * 1000 / zoom
);
563 if (tempColor
!= CLR_INVALID
)
565 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
567 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
572 if (wParam
== VK_ESCAPE
)
577 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
579 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
580 whilePaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
581 endPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
582 ShowWindow(hSelection
, SW_HIDE
);
585 /* FIXME: also cancel current drawing underway */
590 if (hwnd
== hImageArea
)
592 short xNow
= (short)LOWORD(lParam
) * 1000 / zoom
;
593 short yNow
= (short)HIWORD(lParam
) * 1000 / zoom
;
594 if ((!drawing
) || (activeTool
<= TOOL_AIRBRUSH
))
598 if (activeTool
== TOOL_ZOOM
)
600 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
601 drawZoomFrame((short)LOWORD(lParam
), (short)HIWORD(lParam
));
604 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
605 tme
.dwFlags
= TME_LEAVE
;
606 tme
.hwndTrack
= hImageArea
;
608 TrackMouseEvent(&tme
);
613 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
614 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
619 /* values displayed in statusbar */
620 short xRel
= xNow
- startX
;
621 short yRel
= yNow
- startY
;
622 /* freesel, rectsel and text tools always show numbers limited to fit into image area */
623 if ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_TEXT
))
626 xRel
= (xNow
< 0) ? -startX
: xRel
;
627 else if (xNow
> imgXRes
)
628 xRel
= imgXRes
-startX
;
630 yRel
= (yNow
< 0) ? -startY
: yRel
;
631 else if (yNow
> imgYRes
)
632 yRel
= imgYRes
-startY
;
634 /* rectsel and shape tools always show non-negative numbers when drawing */
635 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_SHAPE
))
642 /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
652 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
653 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
657 if ((wParam
& MK_LBUTTON
) != 0)
659 whilePaintingL(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
660 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
661 if ((activeTool
>= TOOL_TEXT
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
664 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
666 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
667 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
670 if ((wParam
& MK_RBUTTON
) != 0)
672 whilePaintingR(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
673 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
674 if (activeTool
>= TOOL_TEXT
)
677 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
679 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
680 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
688 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
689 if (activeTool
== TOOL_ZOOM
)
690 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
693 // menu and button events
695 case WM_SYSCOLORCHANGE
:
697 /* Redirect message to common controls */
698 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
699 SendMessage(hToolbar
, WM_SYSCOLORCHANGE
, 0, 0);
704 switch (LOWORD(wParam
))
708 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
709 TCHAR infotitle
[100];
711 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
712 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
713 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
714 DeleteObject(paintIcon
);
717 case IDM_HELPHELPTOPICS
:
718 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
721 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
724 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
725 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
728 if (GetOpenFileName(&ofn
) != 0)
730 HBITMAP bmNew
= NULL
;
731 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
736 insertReversible(bmNew
);
737 updateCanvasAndScrollbars();
738 CopyMemory(filename
, ofn
.lpstrFileTitle
, sizeof(filename
));
739 CopyMemory(filepathname
, ofn
.lpstrFileTitle
, sizeof(filepathname
));
740 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
741 _stprintf(tempstr
, resstr
, filename
);
742 SetWindowText(hMainWnd
, tempstr
);
751 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
756 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
759 if (GetSaveFileName(&sfn
) != 0)
763 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
765 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
766 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
767 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
768 _stprintf(tempstr
, resstr
, filename
);
769 SetWindowText(hMainWnd
, tempstr
);
774 case IDM_FILEASWALLPAPERPLANE
:
775 SetWallpaper(filepathname
, 1, 1);
777 case IDM_FILEASWALLPAPERCENTERED
:
778 SetWallpaper(filepathname
, 1, 0);
780 case IDM_FILEASWALLPAPERSTRETCHED
:
781 SetWallpaper(filepathname
, 2, 0);
785 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
789 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
792 OpenClipboard(hMainWnd
);
794 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
798 OpenClipboard(hMainWnd
);
799 if (GetClipboardData(CF_BITMAP
) != NULL
)
801 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
),
805 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
806 rectSel_dest
[0] = rectSel_dest
[1] = 0;
807 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
808 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
809 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
810 hSelDC
, 0, 0, SRCCOPY
);
812 ShowWindow(hSelection
, SW_SHOW
);
816 case IDM_EDITDELETESELECTION
:
818 /* remove selection window and already painted content using undo(),
819 paint Rect for rectangular selections and Poly for freeform selections */
821 if (activeTool
== TOOL_RECTSEL
)
824 Rect(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2] + rectSel_dest
[0],
825 rectSel_dest
[3] + rectSel_dest
[1], bgColor
, bgColor
, 0, TRUE
);
827 if (activeTool
== TOOL_FREESEL
)
830 Poly(hDrawingDC
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
834 case IDM_EDITSELECTALL
:
836 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
837 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
838 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
839 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
840 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
841 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
845 if (GetSaveFileName(&ofn
) != 0)
846 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
848 case IDM_COLORSEDITPALETTE
:
849 if (ChooseColor(&choosecolor
))
851 fgColor
= choosecolor
.rgbResult
;
852 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
855 case IDM_IMAGEINVERTCOLORS
:
859 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
860 InvertRect(hDrawingDC
, &tempRect
);
861 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
864 case IDM_IMAGEDELETEIMAGE
:
866 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
867 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
869 case IDM_IMAGEROTATEMIRROR
:
870 switch (mirrorRotateDlg())
872 case 1: /* flip horizontally */
873 if (IsWindowVisible(hSelection
))
875 SelectObject(hSelDC
, hSelMask
);
876 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
877 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
878 SelectObject(hSelDC
, hSelBm
);
879 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
880 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
881 /* force refresh of selection contents, used also in case 2 and case 4 */
882 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
883 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
884 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
889 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
890 imgXRes
, imgYRes
, SRCCOPY
);
891 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
894 case 2: /* flip vertically */
895 if (IsWindowVisible(hSelection
))
897 SelectObject(hSelDC
, hSelMask
);
898 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
899 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
900 SelectObject(hSelDC
, hSelBm
);
901 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
902 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
903 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
904 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
905 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
910 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
911 imgXRes
, imgYRes
, SRCCOPY
);
912 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
915 case 3: /* rotate 90 degrees */
917 case 4: /* rotate 180 degrees */
918 if (IsWindowVisible(hSelection
))
920 SelectObject(hSelDC
, hSelMask
);
921 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
922 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
923 SelectObject(hSelDC
, hSelBm
);
924 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
925 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
926 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
927 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
928 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
933 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
934 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
935 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
938 case 5: /* rotate 270 degrees */
942 case IDM_IMAGEATTRIBUTES
:
944 int retVal
= attributesDlg();
945 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
947 cropReversible(LOWORD(retVal
), HIWORD(retVal
), 0, 0);
948 updateCanvasAndScrollbars();
952 case IDM_IMAGECHANGESIZE
:
954 int retVal
= changeSizeDlg();
955 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
957 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
958 imgXRes
* LOWORD(retVal
) / 100,
959 imgYRes
* HIWORD(retVal
) / 100, 0));
960 updateCanvasAndScrollbars();
964 case IDM_IMAGEDRAWOPAQUE
:
965 transpBg
= 1 - transpBg
;
966 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
969 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
970 updateCanvasAndScrollbars();
973 case IDM_VIEWTOOLBOX
:
974 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
975 alignChildrenToMainWindow();
977 case IDM_VIEWCOLORPALETTE
:
978 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
979 alignChildrenToMainWindow();
981 case IDM_VIEWSTATUSBAR
:
982 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
983 alignChildrenToMainWindow();
986 case IDM_VIEWSHOWGRID
:
987 showGrid
= !showGrid
;
988 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
990 case IDM_VIEWSHOWMINIATURE
:
991 showMiniature
= !showMiniature
;
992 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
995 case IDM_VIEWZOOM125
:
1001 case IDM_VIEWZOOM50
:
1004 case IDM_VIEWZOOM100
:
1007 case IDM_VIEWZOOM200
:
1010 case IDM_VIEWZOOM400
:
1013 case IDM_VIEWZOOM800
:
1067 return DefWindowProc(hwnd
, message
, wParam
, lParam
);