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
);
717 TCHAR programname
[20];
718 TCHAR saveprompttext
[100];
720 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
721 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
722 _stprintf(temptext
, saveprompttext
, filename
);
723 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
729 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
736 if (reset
&& imageSaved
)
738 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
739 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
740 updateCanvasAndScrollbars();
746 if (GetOpenFileName(&ofn
) != 0)
748 HBITMAP bmNew
= NULL
;
749 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
754 insertReversible(bmNew
);
755 updateCanvasAndScrollbars();
756 CopyMemory(filename
, ofn
.lpstrFileTitle
, sizeof(filename
));
757 CopyMemory(filepathname
, ofn
.lpstrFileTitle
, sizeof(filepathname
));
758 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
759 _stprintf(tempstr
, resstr
, filename
);
760 SetWindowText(hMainWnd
, tempstr
);
769 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
774 SendMessage(hwnd
, WM_COMMAND
, IDM_FILESAVEAS
, 0);
777 if (GetSaveFileName(&sfn
) != 0)
781 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
783 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
784 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
785 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
786 _stprintf(tempstr
, resstr
, filename
);
787 SetWindowText(hMainWnd
, tempstr
);
792 case IDM_FILEASWALLPAPERPLANE
:
793 SetWallpaper(filepathname
, 1, 1);
795 case IDM_FILEASWALLPAPERCENTERED
:
796 SetWallpaper(filepathname
, 1, 0);
798 case IDM_FILEASWALLPAPERSTRETCHED
:
799 SetWallpaper(filepathname
, 2, 0);
803 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
807 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
810 OpenClipboard(hMainWnd
);
812 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
817 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITCOPY
, 0);
818 /* Delete selection */
819 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITDELETESELECTION
, 0);
822 OpenClipboard(hMainWnd
);
823 if (GetClipboardData(CF_BITMAP
) != NULL
)
825 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
826 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
827 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
829 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
),
833 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
834 rectSel_dest
[0] = rectSel_dest
[1] = 0;
835 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
836 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
837 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
838 hSelDC
, 0, 0, SRCCOPY
);
840 ShowWindow(hSelection
, SW_SHOW
);
844 case IDM_EDITDELETESELECTION
:
846 /* remove selection window and already painted content using undo(),
847 paint Rect for rectangular selections and Poly for freeform selections */
849 if (activeTool
== TOOL_RECTSEL
)
852 Rect(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2] + rectSel_dest
[0],
853 rectSel_dest
[3] + rectSel_dest
[1], bgColor
, bgColor
, 0, TRUE
);
855 if (activeTool
== TOOL_FREESEL
)
858 Poly(hDrawingDC
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
862 case IDM_EDITSELECTALL
:
864 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
865 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
866 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
867 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
868 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
869 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
873 if (GetSaveFileName(&ofn
) != 0)
874 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
876 case IDM_COLORSEDITPALETTE
:
877 if (ChooseColor(&choosecolor
))
879 fgColor
= choosecolor
.rgbResult
;
880 SendMessage(hPalWin
, WM_PAINT
, 0, 0);
883 case IDM_IMAGEINVERTCOLORS
:
887 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
888 InvertRect(hDrawingDC
, &tempRect
);
889 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
892 case IDM_IMAGEDELETEIMAGE
:
894 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
895 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
897 case IDM_IMAGEROTATEMIRROR
:
898 switch (mirrorRotateDlg())
900 case 1: /* flip horizontally */
901 if (IsWindowVisible(hSelection
))
903 SelectObject(hSelDC
, hSelMask
);
904 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
905 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
906 SelectObject(hSelDC
, hSelBm
);
907 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
908 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
909 /* force refresh of selection contents, used also in case 2 and case 4 */
910 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
911 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
912 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
917 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
918 imgXRes
, imgYRes
, SRCCOPY
);
919 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
922 case 2: /* flip vertically */
923 if (IsWindowVisible(hSelection
))
925 SelectObject(hSelDC
, hSelMask
);
926 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
927 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
928 SelectObject(hSelDC
, hSelBm
);
929 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
930 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
931 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
932 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
933 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
938 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
939 imgXRes
, imgYRes
, SRCCOPY
);
940 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
943 case 3: /* rotate 90 degrees */
945 case 4: /* rotate 180 degrees */
946 if (IsWindowVisible(hSelection
))
948 SelectObject(hSelDC
, hSelMask
);
949 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
950 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
951 SelectObject(hSelDC
, hSelBm
);
952 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
953 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
954 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
955 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
956 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
961 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
962 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
963 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
966 case 5: /* rotate 270 degrees */
970 case IDM_IMAGEATTRIBUTES
:
972 int retVal
= attributesDlg();
973 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
975 cropReversible(LOWORD(retVal
), HIWORD(retVal
), 0, 0);
976 updateCanvasAndScrollbars();
980 case IDM_IMAGECHANGESIZE
:
982 int retVal
= changeSizeDlg();
983 if ((LOWORD(retVal
) != 0) && (HIWORD(retVal
) != 0))
985 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
986 imgXRes
* LOWORD(retVal
) / 100,
987 imgYRes
* HIWORD(retVal
) / 100, 0));
988 updateCanvasAndScrollbars();
992 case IDM_IMAGEDRAWOPAQUE
:
993 transpBg
= 1 - transpBg
;
994 SendMessage(hToolSettings
, WM_PAINT
, 0, 0);
997 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
998 updateCanvasAndScrollbars();
1001 case IDM_VIEWTOOLBOX
:
1002 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
1003 alignChildrenToMainWindow();
1005 case IDM_VIEWCOLORPALETTE
:
1006 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
1007 alignChildrenToMainWindow();
1009 case IDM_VIEWSTATUSBAR
:
1010 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
1011 alignChildrenToMainWindow();
1014 case IDM_VIEWSHOWGRID
:
1015 showGrid
= !showGrid
;
1016 SendMessage(hImageArea
, WM_PAINT
, 0, 0);
1018 case IDM_VIEWSHOWMINIATURE
:
1019 showMiniature
= !showMiniature
;
1020 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
1023 case IDM_VIEWZOOM125
:
1026 case IDM_VIEWZOOM25
:
1029 case IDM_VIEWZOOM50
:
1032 case IDM_VIEWZOOM100
:
1035 case IDM_VIEWZOOM200
:
1038 case IDM_VIEWZOOM400
:
1041 case IDM_VIEWZOOM800
:
1095 return DefWindowProc(hwnd
, message
, wParam
, lParam
);