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 *********************************************************/
12 //#include <htmlhelp.h>
15 /* FUNCTIONS ********************************************************/
20 ShowWindow(hSelection
, SW_HIDE
);
22 pointSP
= 0; // resets the point-buffer of the polygon and bezier functions
23 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
24 ShowWindow(hTrackbarZoom
, (tool
== 6) ? SW_SHOW
: SW_HIDE
);
28 updateCanvasAndScrollbars()
30 ShowWindow(hSelection
, SW_HIDE
);
31 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
32 InvalidateRect(hScrollbox
, NULL
, TRUE
);
33 InvalidateRect(hImageArea
, NULL
, FALSE
);
35 SetScrollPos(hScrollbox
, SB_HORZ
, 0, TRUE
);
36 SetScrollPos(hScrollbox
, SB_VERT
, 0, TRUE
);
40 zoomTo(int newZoom
, int mouseX
, int mouseY
)
43 int tempZoom
= newZoom
;
45 long clientRectScrollbox
[4];
46 long clientRectImageArea
[4];
48 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
49 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
50 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * newZoom
/ zoom
);
51 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * newZoom
/ zoom
);
52 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2)) * newZoom
/ zoom
;
53 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2)) * newZoom
/ zoom
;
57 ShowWindow(hSelection
, SW_HIDE
);
58 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
59 InvalidateRect(hScrollbox
, NULL
, TRUE
);
60 InvalidateRect(hImageArea
, NULL
, FALSE
);
62 SendMessage(hScrollbox
, WM_HSCROLL
, SB_THUMBPOSITION
| (x
<< 16), 0);
63 SendMessage(hScrollbox
, WM_VSCROLL
, SB_THUMBPOSITION
| (y
<< 16), 0);
65 while (tempZoom
> 125)
68 tempZoom
= tempZoom
>> 1;
70 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) tbPos
);
74 drawZoomFrame(int mouseX
, int mouseY
)
82 long clientRectScrollbox
[4];
83 long clientRectImageArea
[4];
85 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
86 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
87 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * 2);
88 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * 2);
89 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2));
90 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2));
92 hdc
= GetDC(hImageArea
);
93 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, 0));
94 logbrush
.lbStyle
= BS_HOLLOW
;
95 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
96 rop
= SetROP2(hdc
, R2_NOT
);
97 Rectangle(hdc
, x
, y
, x
+ w
, y
+ h
);
99 DeleteObject(SelectObject(hdc
, oldBrush
));
100 DeleteObject(SelectObject(hdc
, oldPen
));
101 ReleaseDC(hImageArea
, hdc
);
105 alignChildrenToMainWindow()
109 GetClientRect(hMainWnd
, &clientRect
);
111 if (IsWindowVisible(hToolBoxContainer
))
114 w
= clientRect
.right
- 56;
119 w
= clientRect
.right
;
121 if (IsWindowVisible(hPalWin
))
124 h
= clientRect
.bottom
- 49;
129 h
= clientRect
.bottom
- 3;
132 MoveWindow(hScrollbox
, x
, y
, w
, IsWindowVisible(hStatusBar
) ? h
- 23 : h
, TRUE
);
133 MoveWindow(hPalWin
, x
, 9, 255, 32, TRUE
);
139 WindowProcedure(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
141 switch (message
) /* handle the messages */
149 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
153 if (hwnd
== hwndMiniature
)
155 ShowWindow(hwndMiniature
, SW_HIDE
);
156 showMiniature
= FALSE
;
161 TCHAR programname
[20];
162 TCHAR saveprompttext
[100];
164 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
165 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
166 _stprintf(temptext
, saveprompttext
, filename
);
167 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
173 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
184 case WM_INITMENUPOPUP
:
190 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
191 MF_ENABLED
| MF_BYCOMMAND
);
192 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
193 MF_ENABLED
| MF_BYCOMMAND
);
194 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
195 MF_ENABLED
| MF_BYCOMMAND
);
199 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
200 MF_GRAYED
| MF_BYCOMMAND
);
201 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
202 MF_GRAYED
| MF_BYCOMMAND
);
203 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
204 MF_GRAYED
| MF_BYCOMMAND
);
208 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
,
209 (undoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
210 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
,
211 (redoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
212 if (IsWindowVisible(hSelection
))
214 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_ENABLED
| MF_BYCOMMAND
);
215 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_ENABLED
| MF_BYCOMMAND
);
216 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
217 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
218 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_ENABLED
| MF_BYCOMMAND
);
222 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_GRAYED
| MF_BYCOMMAND
);
223 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_GRAYED
| MF_BYCOMMAND
);
224 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
225 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
226 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_GRAYED
| MF_BYCOMMAND
);
228 OpenClipboard(hMainWnd
);
229 if (GetClipboardData(CF_BITMAP
) != NULL
)
230 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_ENABLED
| MF_BYCOMMAND
);
232 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_GRAYED
| MF_BYCOMMAND
);
236 if (IsWindowVisible(hSelection
))
237 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_ENABLED
| MF_BYCOMMAND
);
239 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_GRAYED
| MF_BYCOMMAND
);
240 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, (transpBg
== 0) ?
241 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
244 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWTOOLBOX
,
245 IsWindowVisible(hToolBoxContainer
) ?
246 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
247 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWCOLORPALETTE
,
248 IsWindowVisible(hPalWin
) ?
249 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
250 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
,
251 IsWindowVisible(hStatusBar
) ?
252 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
254 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
,
255 showGrid
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
256 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
,
257 showMiniature
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
259 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
,
260 (zoom
== 125) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
261 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
,
262 (zoom
== 250) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
263 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
,
264 (zoom
== 500) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
265 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
,
266 (zoom
== 1000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
267 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
,
268 (zoom
== 2000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
269 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
,
270 (zoom
== 4000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
271 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
,
272 (zoom
== 8000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
277 if (hwnd
== hMainWnd
)
279 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
280 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
281 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (LPARAM
)&test
);
282 alignChildrenToMainWindow();
284 if (hwnd
== hImageArea
)
286 MoveWindow(hSizeboxLeftTop
,
289 MoveWindow(hSizeboxCenterTop
,
290 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
292 MoveWindow(hSizeboxRightTop
,
293 imgXRes
* zoom
/ 1000 + 3,
295 MoveWindow(hSizeboxLeftCenter
,
297 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
298 MoveWindow(hSizeboxRightCenter
,
299 imgXRes
* zoom
/ 1000 + 3,
300 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
301 MoveWindow(hSizeboxLeftBottom
,
303 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
304 MoveWindow(hSizeboxCenterBottom
,
305 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
306 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
307 MoveWindow(hSizeboxRightBottom
,
308 imgXRes
* zoom
/ 1000 + 3,
309 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
311 if ((hwnd
== hImageArea
) || (hwnd
== hScrollbox
))
313 long clientRectScrollbox
[4];
314 long clientRectImageArea
[4];
316 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
317 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
318 si
.cbSize
= sizeof(SCROLLINFO
);
319 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
320 si
.nMax
= clientRectImageArea
[2] + 6 - 1;
322 si
.nPage
= clientRectScrollbox
[2];
323 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
324 GetClientRect(hScrollbox
, (LPRECT
) clientRectScrollbox
);
325 si
.nMax
= clientRectImageArea
[3] + 6 - 1;
326 si
.nPage
= clientRectScrollbox
[3];
327 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
328 MoveWindow(hScrlClient
,
329 -GetScrollPos(hScrollbox
, SB_HORZ
), -GetScrollPos(hScrollbox
, SB_VERT
),
330 max(clientRectImageArea
[2] + 6, clientRectScrollbox
[2]),
331 max(clientRectImageArea
[3] + 6, clientRectScrollbox
[3]), TRUE
);
336 if (hwnd
== hScrollbox
)
339 si
.cbSize
= sizeof(SCROLLINFO
);
341 GetScrollInfo(hScrollbox
, SB_HORZ
, &si
);
342 switch (LOWORD(wParam
))
345 case SB_THUMBPOSITION
:
346 si
.nPos
= HIWORD(wParam
);
361 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
362 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
363 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
364 imgYRes
* zoom
/ 1000 + 6, TRUE
);
369 if (hwnd
== hScrollbox
)
372 si
.cbSize
= sizeof(SCROLLINFO
);
374 GetScrollInfo(hScrollbox
, SB_VERT
, &si
);
375 switch (LOWORD(wParam
))
378 case SB_THUMBPOSITION
:
379 si
.nPos
= HIWORD(wParam
);
394 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
395 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
396 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
397 imgYRes
* zoom
/ 1000 + 6, TRUE
);
401 case WM_GETMINMAXINFO
:
402 if (hwnd
== hMainWnd
)
404 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
405 (*mm
).ptMinTrackSize
.x
= 330;
406 (*mm
).ptMinTrackSize
.y
= 430;
411 DefWindowProc(hwnd
, message
, wParam
, lParam
);
412 if (hwnd
== hImageArea
)
414 HDC hdc
= GetDC(hImageArea
);
415 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
417 if (showGrid
&& (zoom
>= 4000))
419 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
421 for(counter
= 0; counter
<= imgYRes
; counter
++)
423 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
424 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
426 for(counter
= 0; counter
<= imgXRes
; counter
++)
428 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
429 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
431 DeleteObject(SelectObject(hdc
, oldPen
));
433 ReleaseDC(hImageArea
, hdc
);
434 SendMessage(hSelection
, WM_PAINT
, 0, 0);
435 SendMessage(hwndMiniature
, WM_PAINT
, 0, 0);
437 else if (hwnd
== hwndMiniature
)
441 GetClientRect(hwndMiniature
, &mclient
);
442 hdc
= GetDC(hwndMiniature
);
443 StretchBlt(hdc
, 0, 0, mclient
.right
, mclient
.bottom
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
444 ReleaseDC(hwndMiniature
, hdc
);
448 // mouse events used for drawing
451 if (hwnd
== hImageArea
)
459 SetCursor(hCurColor
);
468 SetCursor(hCurAirbrush
);
471 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
475 DefWindowProc(hwnd
, message
, wParam
, lParam
);
479 if (hwnd
== hImageArea
)
481 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
483 SetCapture(hImageArea
);
485 startPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
490 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
493 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
494 if ((activeTool
== TOOL_ZOOM
) && (zoom
< 8000))
495 zoomTo(zoom
* 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
500 if (hwnd
== hImageArea
)
502 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
504 SetCapture(hImageArea
);
506 startPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
511 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
514 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
515 if ((activeTool
== TOOL_ZOOM
) && (zoom
> 125))
516 zoomTo(zoom
/ 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
521 if ((hwnd
== hImageArea
) && drawing
)
525 endPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
527 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
528 if (activeTool
== TOOL_COLOR
)
531 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
532 if (tempColor
!= CLR_INVALID
)
534 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
536 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
541 if ((hwnd
== hImageArea
) && drawing
)
545 endPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
547 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
548 if (activeTool
== TOOL_COLOR
)
551 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
552 if (tempColor
!= CLR_INVALID
)
554 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
556 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
561 if (wParam
== VK_ESCAPE
)
566 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
568 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
569 whilePaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
570 endPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
571 ShowWindow(hSelection
, SW_HIDE
);
574 /* FIXME: also cancel current drawing underway */
579 if (hwnd
== hImageArea
)
581 LONG xNow
= GET_X_LPARAM(lParam
) * 1000 / zoom
;
582 LONG yNow
= GET_Y_LPARAM(lParam
) * 1000 / zoom
;
583 if ((!drawing
) || (activeTool
<= TOOL_AIRBRUSH
))
587 if (activeTool
== TOOL_ZOOM
)
589 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
590 drawZoomFrame(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
593 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
594 tme
.dwFlags
= TME_LEAVE
;
595 tme
.hwndTrack
= hImageArea
;
597 TrackMouseEvent(&tme
);
602 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
603 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
608 /* values displayed in statusbar */
609 LONG xRel
= xNow
- startX
;
610 LONG yRel
= yNow
- startY
;
611 /* freesel, rectsel and text tools always show numbers limited to fit into image area */
612 if ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_TEXT
))
615 xRel
= (xNow
< 0) ? -startX
: xRel
;
616 else if (xNow
> imgXRes
)
617 xRel
= imgXRes
-startX
;
619 yRel
= (yNow
< 0) ? -startY
: yRel
;
620 else if (yNow
> imgYRes
)
621 yRel
= imgYRes
-startY
;
623 /* rectsel and shape tools always show non-negative numbers when drawing */
624 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_SHAPE
))
631 /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
641 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
642 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
646 if ((wParam
& MK_LBUTTON
) != 0)
648 whilePaintingL(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
649 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
650 if ((activeTool
>= TOOL_TEXT
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
653 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
655 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
656 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
659 if ((wParam
& MK_RBUTTON
) != 0)
661 whilePaintingR(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
662 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
663 if (activeTool
>= TOOL_TEXT
)
666 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
668 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
669 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
677 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
678 if (activeTool
== TOOL_ZOOM
)
679 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
682 // menu and button events
684 case WM_SYSCOLORCHANGE
:
686 /* Redirect message to common controls */
687 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
688 SendMessage(hToolbar
, WM_SYSCOLORCHANGE
, 0, 0);
693 switch (LOWORD(wParam
))
697 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
698 TCHAR infotitle
[100];
700 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
701 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
702 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
703 DeleteObject(paintIcon
);
706 case IDM_HELPHELPTOPICS
:
707 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
710 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
713 ShowWindow(hSelection
, SW_HIDE
);
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
));
791 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITCOPY
, 0);
792 /* Delete selection */
793 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITDELETESELECTION
, 0);
796 OpenClipboard(hMainWnd
);
797 if (GetClipboardData(CF_BITMAP
) != NULL
)
799 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
800 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
801 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
803 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
),
807 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
808 rectSel_dest
[0] = rectSel_dest
[1] = 0;
809 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
810 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
811 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
812 hSelDC
, 0, 0, SRCCOPY
);
814 ShowWindow(hSelection
, SW_SHOW
);
818 case IDM_EDITDELETESELECTION
:
820 /* remove selection window and already painted content using undo(),
821 paint Rect for rectangular selections and Poly for freeform selections */
823 if (activeTool
== TOOL_RECTSEL
)
826 Rect(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2] + rectSel_dest
[0],
827 rectSel_dest
[3] + rectSel_dest
[1], bgColor
, bgColor
, 0, TRUE
);
829 if (activeTool
== TOOL_FREESEL
)
832 Poly(hDrawingDC
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
836 case IDM_EDITSELECTALL
:
838 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
839 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
840 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
841 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
842 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
843 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
847 if (GetSaveFileName(&ofn
) != 0)
848 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
850 case IDM_COLORSEDITPALETTE
:
851 if (ChooseColor(&choosecolor
))
853 fgColor
= choosecolor
.rgbResult
;
854 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
857 case IDM_IMAGEINVERTCOLORS
:
861 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
862 InvertRect(hDrawingDC
, &tempRect
);
863 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
866 case IDM_IMAGEDELETEIMAGE
:
868 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
869 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
871 case IDM_IMAGEROTATEMIRROR
:
872 switch (mirrorRotateDlg())
874 case 1: /* flip horizontally */
875 if (IsWindowVisible(hSelection
))
877 SelectObject(hSelDC
, hSelMask
);
878 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
879 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
880 SelectObject(hSelDC
, hSelBm
);
881 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
882 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
883 /* force refresh of selection contents, used also in case 2 and case 4 */
884 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
885 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
886 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
891 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
892 imgXRes
, imgYRes
, SRCCOPY
);
893 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
896 case 2: /* flip vertically */
897 if (IsWindowVisible(hSelection
))
899 SelectObject(hSelDC
, hSelMask
);
900 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
901 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
902 SelectObject(hSelDC
, hSelBm
);
903 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
904 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
905 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
906 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
907 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
912 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
913 imgXRes
, imgYRes
, SRCCOPY
);
914 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
917 case 3: /* rotate 90 degrees */
919 case 4: /* rotate 180 degrees */
920 if (IsWindowVisible(hSelection
))
922 SelectObject(hSelDC
, hSelMask
);
923 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
924 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
925 SelectObject(hSelDC
, hSelBm
);
926 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
927 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
928 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
929 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
930 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
935 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
936 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
937 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
940 case 5: /* rotate 270 degrees */
944 case IDM_IMAGEATTRIBUTES
:
946 int retVal
= attributesDlg();
947 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
949 cropReversible(LOWORD(retVal
), HIWORD(retVal
), 0, 0);
950 updateCanvasAndScrollbars();
954 case IDM_IMAGECHANGESIZE
:
956 int retVal
= changeSizeDlg();
957 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
959 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
960 imgXRes
* LOWORD(retVal
) / 100,
961 imgYRes
* HIWORD(retVal
) / 100, 0));
962 updateCanvasAndScrollbars();
966 case IDM_IMAGEDRAWOPAQUE
:
967 transpBg
= 1 - transpBg
;
968 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
971 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
972 updateCanvasAndScrollbars();
975 case IDM_VIEWTOOLBOX
:
976 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
977 alignChildrenToMainWindow();
979 case IDM_VIEWCOLORPALETTE
:
980 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
981 alignChildrenToMainWindow();
983 case IDM_VIEWSTATUSBAR
:
984 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
985 alignChildrenToMainWindow();
988 case IDM_VIEWSHOWGRID
:
989 showGrid
= !showGrid
;
990 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
992 case IDM_VIEWSHOWMINIATURE
:
993 showMiniature
= !showMiniature
;
994 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
997 case IDM_VIEWZOOM125
:
1000 case IDM_VIEWZOOM25
:
1003 case IDM_VIEWZOOM50
:
1006 case IDM_VIEWZOOM100
:
1009 case IDM_VIEWZOOM200
:
1012 case IDM_VIEWZOOM400
:
1015 case IDM_VIEWZOOM800
:
1069 return DefWindowProc(hwnd
, message
, wParam
, lParam
);