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
696 switch (LOWORD(wParam
))
700 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
701 TCHAR infotitle
[100];
703 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
704 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
705 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
706 DeleteObject(paintIcon
);
709 case IDM_HELPHELPTOPICS
:
710 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
713 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
716 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
717 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
720 if (GetOpenFileName(&ofn
) != 0)
722 HBITMAP bmNew
= NULL
;
723 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
728 insertReversible(bmNew
);
729 updateCanvasAndScrollbars();
730 CopyMemory(filename
, ofn
.lpstrFileTitle
, sizeof(filename
));
731 CopyMemory(filepathname
, ofn
.lpstrFileTitle
, sizeof(filepathname
));
732 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
733 _stprintf(tempstr
, resstr
, filename
);
734 SetWindowText(hMainWnd
, tempstr
);
743 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
748 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
751 if (GetSaveFileName(&sfn
) != 0)
755 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
757 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
758 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
759 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
760 _stprintf(tempstr
, resstr
, filename
);
761 SetWindowText(hMainWnd
, tempstr
);
766 case IDM_FILEASWALLPAPERPLANE
:
767 SetWallpaper(filepathname
, 1, 1);
769 case IDM_FILEASWALLPAPERCENTERED
:
770 SetWallpaper(filepathname
, 1, 0);
772 case IDM_FILEASWALLPAPERSTRETCHED
:
773 SetWallpaper(filepathname
, 2, 0);
777 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
781 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
784 OpenClipboard(hMainWnd
);
786 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
790 OpenClipboard(hMainWnd
);
791 if (GetClipboardData(CF_BITMAP
) != NULL
)
793 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
),
797 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
798 rectSel_dest
[0] = rectSel_dest
[1] = 0;
799 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
800 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
801 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
802 hSelDC
, 0, 0, SRCCOPY
);
804 ShowWindow(hSelection
, SW_SHOW
);
808 case IDM_EDITDELETESELECTION
:
810 /* remove selection window and already painted content using undo(),
811 paint Rect for rectangular selections and Poly for freeform selections */
813 if (activeTool
== TOOL_RECTSEL
)
816 Rect(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2] + rectSel_dest
[0],
817 rectSel_dest
[3] + rectSel_dest
[1], bgColor
, bgColor
, 0, TRUE
);
819 if (activeTool
== TOOL_FREESEL
)
822 Poly(hDrawingDC
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
826 case IDM_EDITSELECTALL
:
828 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
829 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
830 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
831 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
832 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
833 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
837 if (GetSaveFileName(&ofn
) != 0)
838 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
840 case IDM_COLORSEDITPALETTE
:
841 if (ChooseColor(&choosecolor
))
843 fgColor
= choosecolor
.rgbResult
;
844 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
847 case IDM_IMAGEINVERTCOLORS
:
851 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
852 InvertRect(hDrawingDC
, &tempRect
);
853 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
856 case IDM_IMAGEDELETEIMAGE
:
858 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
859 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
861 case IDM_IMAGEROTATEMIRROR
:
862 switch (mirrorRotateDlg())
864 case 1: /* flip horizontally */
865 if (IsWindowVisible(hSelection
))
867 SelectObject(hSelDC
, hSelMask
);
868 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
869 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
870 SelectObject(hSelDC
, hSelBm
);
871 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
872 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
873 /* force refresh of selection contents, used also in case 2 and case 4 */
874 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
875 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
876 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
881 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
882 imgXRes
, imgYRes
, SRCCOPY
);
883 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
886 case 2: /* flip vertically */
887 if (IsWindowVisible(hSelection
))
889 SelectObject(hSelDC
, hSelMask
);
890 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
891 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
892 SelectObject(hSelDC
, hSelBm
);
893 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
894 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
895 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
896 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
897 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
902 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
903 imgXRes
, imgYRes
, SRCCOPY
);
904 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
907 case 3: /* rotate 90 degrees */
909 case 4: /* rotate 180 degrees */
910 if (IsWindowVisible(hSelection
))
912 SelectObject(hSelDC
, hSelMask
);
913 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
914 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
915 SelectObject(hSelDC
, hSelBm
);
916 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
917 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
918 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
919 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
920 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
925 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
926 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
927 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
930 case 5: /* rotate 270 degrees */
934 case IDM_IMAGEATTRIBUTES
:
936 int retVal
= attributesDlg();
937 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
939 cropReversible(LOWORD(retVal
), HIWORD(retVal
), 0, 0);
940 updateCanvasAndScrollbars();
944 case IDM_IMAGECHANGESIZE
:
946 int retVal
= changeSizeDlg();
947 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
949 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
950 imgXRes
* LOWORD(retVal
) / 100,
951 imgYRes
* HIWORD(retVal
) / 100, 0));
952 updateCanvasAndScrollbars();
956 case IDM_IMAGEDRAWOPAQUE
:
957 transpBg
= 1 - transpBg
;
958 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
961 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
962 updateCanvasAndScrollbars();
965 case IDM_VIEWTOOLBOX
:
966 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
967 alignChildrenToMainWindow();
969 case IDM_VIEWCOLORPALETTE
:
970 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
971 alignChildrenToMainWindow();
973 case IDM_VIEWSTATUSBAR
:
974 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
975 alignChildrenToMainWindow();
978 case IDM_VIEWSHOWGRID
:
979 showGrid
= !showGrid
;
980 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
982 case IDM_VIEWSHOWMINIATURE
:
983 showMiniature
= !showMiniature
;
984 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
987 case IDM_VIEWZOOM125
:
996 case IDM_VIEWZOOM100
:
999 case IDM_VIEWZOOM200
:
1002 case IDM_VIEWZOOM400
:
1005 case IDM_VIEWZOOM800
:
1059 return DefWindowProc(hwnd
, message
, wParam
, lParam
);