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 InvalidateRect(hToolSettings
, NULL
, TRUE
);
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
);
137 saveImage(BOOL overwrite
)
139 if (isAFile
&& overwrite
)
141 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
145 else if (GetSaveFileName(&sfn
) != 0)
149 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
151 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
152 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
153 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
154 _stprintf(tempstr
, resstr
, filename
);
155 SetWindowText(hMainWnd
, tempstr
);
164 WindowProcedure(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
166 switch (message
) /* handle the messages */
174 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
178 if (hwnd
== hwndMiniature
)
180 ShowWindow(hwndMiniature
, SW_HIDE
);
181 showMiniature
= FALSE
;
186 TCHAR programname
[20];
187 TCHAR saveprompttext
[100];
189 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
190 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
191 _stprintf(temptext
, saveprompttext
, filename
);
192 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
210 case WM_INITMENUPOPUP
:
216 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
217 MF_ENABLED
| MF_BYCOMMAND
);
218 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
219 MF_ENABLED
| MF_BYCOMMAND
);
220 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
221 MF_ENABLED
| MF_BYCOMMAND
);
225 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
226 MF_GRAYED
| MF_BYCOMMAND
);
227 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
228 MF_GRAYED
| MF_BYCOMMAND
);
229 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
230 MF_GRAYED
| MF_BYCOMMAND
);
234 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
,
235 (undoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
236 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
,
237 (redoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
238 if (IsWindowVisible(hSelection
))
240 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_ENABLED
| MF_BYCOMMAND
);
241 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_ENABLED
| MF_BYCOMMAND
);
242 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
243 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
244 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_ENABLED
| MF_BYCOMMAND
);
248 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_GRAYED
| MF_BYCOMMAND
);
249 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_GRAYED
| MF_BYCOMMAND
);
250 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
251 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
252 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_GRAYED
| MF_BYCOMMAND
);
254 OpenClipboard(hMainWnd
);
255 if (GetClipboardData(CF_BITMAP
) != NULL
)
256 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_ENABLED
| MF_BYCOMMAND
);
258 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_GRAYED
| MF_BYCOMMAND
);
262 if (IsWindowVisible(hSelection
))
263 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_ENABLED
| MF_BYCOMMAND
);
265 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_GRAYED
| MF_BYCOMMAND
);
266 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, (transpBg
== 0) ?
267 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
270 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWTOOLBOX
,
271 IsWindowVisible(hToolBoxContainer
) ?
272 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
273 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWCOLORPALETTE
,
274 IsWindowVisible(hPalWin
) ?
275 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
276 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
,
277 IsWindowVisible(hStatusBar
) ?
278 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
280 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
,
281 showGrid
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
282 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
,
283 showMiniature
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
285 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
,
286 (zoom
== 125) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
287 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
,
288 (zoom
== 250) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
289 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
,
290 (zoom
== 500) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
291 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
,
292 (zoom
== 1000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
293 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
,
294 (zoom
== 2000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
295 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
,
296 (zoom
== 4000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
297 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
,
298 (zoom
== 8000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
300 CheckMenuItem(GetMenu(hMainWnd
), IDM_COLORSMODERNPALETTE
,
301 (selectedPalette
== 1) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
302 CheckMenuItem(GetMenu(hMainWnd
), IDM_COLORSOLDPALETTE
,
303 (selectedPalette
== 2) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
307 if (hwnd
== hMainWnd
)
309 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
310 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
311 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (LPARAM
)&test
);
312 alignChildrenToMainWindow();
313 InvalidateRect(hwnd
, NULL
, TRUE
);
315 if (hwnd
== hImageArea
)
317 MoveWindow(hSizeboxLeftTop
,
320 MoveWindow(hSizeboxCenterTop
,
321 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
323 MoveWindow(hSizeboxRightTop
,
324 imgXRes
* zoom
/ 1000 + 3,
326 MoveWindow(hSizeboxLeftCenter
,
328 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
329 MoveWindow(hSizeboxRightCenter
,
330 imgXRes
* zoom
/ 1000 + 3,
331 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
332 MoveWindow(hSizeboxLeftBottom
,
334 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
335 MoveWindow(hSizeboxCenterBottom
,
336 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
337 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
338 MoveWindow(hSizeboxRightBottom
,
339 imgXRes
* zoom
/ 1000 + 3,
340 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
342 if ((hwnd
== hImageArea
) || (hwnd
== hScrollbox
))
344 long clientRectScrollbox
[4];
345 long clientRectImageArea
[4];
347 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
348 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
349 si
.cbSize
= sizeof(SCROLLINFO
);
350 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
351 si
.nMax
= clientRectImageArea
[2] + 6 - 1;
353 si
.nPage
= clientRectScrollbox
[2];
354 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
355 GetClientRect(hScrollbox
, (LPRECT
) clientRectScrollbox
);
356 si
.nMax
= clientRectImageArea
[3] + 6 - 1;
357 si
.nPage
= clientRectScrollbox
[3];
358 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
359 MoveWindow(hScrlClient
,
360 -GetScrollPos(hScrollbox
, SB_HORZ
), -GetScrollPos(hScrollbox
, SB_VERT
),
361 max(clientRectImageArea
[2] + 6, clientRectScrollbox
[2]),
362 max(clientRectImageArea
[3] + 6, clientRectScrollbox
[3]), TRUE
);
367 if (hwnd
== hScrollbox
)
370 si
.cbSize
= sizeof(SCROLLINFO
);
372 GetScrollInfo(hScrollbox
, SB_HORZ
, &si
);
373 switch (LOWORD(wParam
))
376 case SB_THUMBPOSITION
:
377 si
.nPos
= HIWORD(wParam
);
392 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
393 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
394 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
395 imgYRes
* zoom
/ 1000 + 6, TRUE
);
400 if (hwnd
== hScrollbox
)
403 si
.cbSize
= sizeof(SCROLLINFO
);
405 GetScrollInfo(hScrollbox
, SB_VERT
, &si
);
406 switch (LOWORD(wParam
))
409 case SB_THUMBPOSITION
:
410 si
.nPos
= HIWORD(wParam
);
425 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
426 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
427 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
428 imgYRes
* zoom
/ 1000 + 6, TRUE
);
432 case WM_GETMINMAXINFO
:
433 if (hwnd
== hMainWnd
)
435 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
436 mm
->ptMinTrackSize
.x
= 330;
437 mm
->ptMinTrackSize
.y
= 430;
442 DefWindowProc(hwnd
, message
, wParam
, lParam
);
443 if (hwnd
== hImageArea
)
445 HDC hdc
= GetDC(hImageArea
);
446 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
448 if (showGrid
&& (zoom
>= 4000))
450 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
452 for(counter
= 0; counter
<= imgYRes
; counter
++)
454 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
455 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
457 for(counter
= 0; counter
<= imgXRes
; counter
++)
459 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
460 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
462 DeleteObject(SelectObject(hdc
, oldPen
));
464 ReleaseDC(hImageArea
, hdc
);
465 InvalidateRect(hSelection
, NULL
, FALSE
);
466 InvalidateRect(hwndMiniature
, NULL
, FALSE
);
468 else if (hwnd
== hwndMiniature
)
472 GetClientRect(hwndMiniature
, &mclient
);
473 hdc
= GetDC(hwndMiniature
);
474 StretchBlt(hdc
, 0, 0, mclient
.right
, mclient
.bottom
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
475 ReleaseDC(hwndMiniature
, hdc
);
479 // mouse events used for drawing
482 if (hwnd
== hImageArea
)
490 SetCursor(hCurColor
);
499 SetCursor(hCurAirbrush
);
502 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
506 DefWindowProc(hwnd
, message
, wParam
, lParam
);
510 if (hwnd
== hImageArea
)
512 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
514 SetCapture(hImageArea
);
516 startPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
521 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
524 InvalidateRect(hImageArea
, NULL
, FALSE
);
525 if ((activeTool
== TOOL_ZOOM
) && (zoom
< 8000))
526 zoomTo(zoom
* 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
531 if (hwnd
== hImageArea
)
533 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
535 SetCapture(hImageArea
);
537 startPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
542 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
545 InvalidateRect(hImageArea
, NULL
, FALSE
);
546 if ((activeTool
== TOOL_ZOOM
) && (zoom
> 125))
547 zoomTo(zoom
/ 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
552 if ((hwnd
== hImageArea
) && drawing
)
556 endPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
558 InvalidateRect(hImageArea
, NULL
, FALSE
);
559 if (activeTool
== TOOL_COLOR
)
562 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
563 if (tempColor
!= CLR_INVALID
)
565 InvalidateRect(hPalWin
, NULL
, FALSE
);
567 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
572 if ((hwnd
== hImageArea
) && drawing
)
576 endPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
578 InvalidateRect(hImageArea
, NULL
, FALSE
);
579 if (activeTool
== TOOL_COLOR
)
582 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
583 if (tempColor
!= CLR_INVALID
)
585 InvalidateRect(hPalWin
, NULL
, FALSE
);
587 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
592 if (wParam
== VK_ESCAPE
)
597 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
599 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
600 whilePaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
601 endPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
602 ShowWindow(hSelection
, SW_HIDE
);
605 /* FIXME: also cancel current drawing underway */
610 if (hwnd
== hImageArea
)
612 LONG xNow
= GET_X_LPARAM(lParam
) * 1000 / zoom
;
613 LONG yNow
= GET_Y_LPARAM(lParam
) * 1000 / zoom
;
614 if ((!drawing
) || (activeTool
<= TOOL_AIRBRUSH
))
618 if (activeTool
== TOOL_ZOOM
)
620 InvalidateRect(hImageArea
, NULL
, FALSE
);
621 UpdateWindow(hImageArea
);
622 drawZoomFrame(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
625 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
626 tme
.dwFlags
= TME_LEAVE
;
627 tme
.hwndTrack
= hImageArea
;
629 TrackMouseEvent(&tme
);
634 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
635 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
640 /* values displayed in statusbar */
641 LONG xRel
= xNow
- start
.x
;
642 LONG yRel
= yNow
- start
.y
;
643 /* freesel, rectsel and text tools always show numbers limited to fit into image area */
644 if ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_TEXT
))
647 xRel
= (xNow
< 0) ? -start
.x
: xRel
;
648 else if (xNow
> imgXRes
)
649 xRel
= imgXRes
-start
.x
;
651 yRel
= (yNow
< 0) ? -start
.y
: yRel
;
652 else if (yNow
> imgYRes
)
653 yRel
= imgYRes
-start
.y
;
655 /* rectsel and shape tools always show non-negative numbers when drawing */
656 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_SHAPE
))
663 /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
673 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
674 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
678 if ((wParam
& MK_LBUTTON
) != 0)
680 whilePaintingL(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
681 InvalidateRect(hImageArea
, NULL
, FALSE
);
682 if ((activeTool
>= TOOL_TEXT
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
685 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
687 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
688 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
691 if ((wParam
& MK_RBUTTON
) != 0)
693 whilePaintingR(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
694 InvalidateRect(hImageArea
, NULL
, FALSE
);
695 if (activeTool
>= TOOL_TEXT
)
698 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
700 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
701 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
709 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
710 if (activeTool
== TOOL_ZOOM
)
711 InvalidateRect(hImageArea
, NULL
, FALSE
);
714 // menu and button events
716 case WM_SYSCOLORCHANGE
:
718 /* Redirect message to common controls */
719 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
720 SendMessage(hToolbar
, WM_SYSCOLORCHANGE
, 0, 0);
725 switch (LOWORD(wParam
))
729 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
730 TCHAR infotitle
[100];
732 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
733 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
734 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
735 DeleteObject(paintIcon
);
738 case IDM_HELPHELPTOPICS
:
739 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
742 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
749 TCHAR programname
[20];
750 TCHAR saveprompttext
[100];
752 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
753 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
754 _stprintf(temptext
, saveprompttext
, filename
);
755 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
768 if (reset
&& imageSaved
)
770 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
771 InvalidateRect(hImageArea
, NULL
, FALSE
);
772 updateCanvasAndScrollbars();
778 if (GetOpenFileName(&ofn
) != 0)
780 HBITMAP bmNew
= NULL
;
781 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
786 insertReversible(bmNew
);
787 updateCanvasAndScrollbars();
788 CopyMemory(filename
, ofn
.lpstrFileTitle
, sizeof(filename
));
789 CopyMemory(filepathname
, ofn
.lpstrFileTitle
, sizeof(filepathname
));
790 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
791 _stprintf(tempstr
, resstr
, filename
);
792 SetWindowText(hMainWnd
, tempstr
);
798 TCHAR programname
[20];
799 TCHAR loaderrortext
[100];
801 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
802 LoadString(hProgInstance
, IDS_LOADERRORTEXT
, loaderrortext
, SIZEOF(loaderrortext
));
803 _stprintf(temptext
, loaderrortext
, ofn
.lpstrFile
);
804 MessageBox(hwnd
, temptext
, programname
, MB_OK
| MB_ICONEXCLAMATION
);
814 case IDM_FILEASWALLPAPERPLANE
:
815 SetWallpaper(filepathname
, 1, 1);
817 case IDM_FILEASWALLPAPERCENTERED
:
818 SetWallpaper(filepathname
, 1, 0);
820 case IDM_FILEASWALLPAPERSTRETCHED
:
821 SetWallpaper(filepathname
, 2, 0);
825 InvalidateRect(hImageArea
, NULL
, FALSE
);
829 InvalidateRect(hImageArea
, NULL
, FALSE
);
832 OpenClipboard(hMainWnd
);
834 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
839 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITCOPY
, 0);
840 /* Delete selection */
841 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITDELETESELECTION
, 0);
844 OpenClipboard(hMainWnd
);
845 if (GetClipboardData(CF_BITMAP
) != NULL
)
847 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
848 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
849 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
851 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(GetClipboardData(CF_BITMAP
),
855 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
856 rectSel_dest
[0] = rectSel_dest
[1] = 0;
857 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
858 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
859 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
860 hSelDC
, 0, 0, SRCCOPY
);
862 ShowWindow(hSelection
, SW_SHOW
);
866 case IDM_EDITDELETESELECTION
:
868 /* remove selection window and already painted content using undo(),
869 paint Rect for rectangular selections and Poly for freeform selections */
871 if (activeTool
== TOOL_RECTSEL
)
874 Rect(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2] + rectSel_dest
[0],
875 rectSel_dest
[3] + rectSel_dest
[1], bgColor
, bgColor
, 0, TRUE
);
877 if (activeTool
== TOOL_FREESEL
)
880 Poly(hDrawingDC
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
884 case IDM_EDITSELECTALL
:
886 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
887 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
888 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
889 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
890 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
891 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
895 if (GetSaveFileName(&ofn
) != 0)
896 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
898 case IDM_COLORSEDITPALETTE
:
899 if (ChooseColor(&choosecolor
))
901 fgColor
= choosecolor
.rgbResult
;
902 InvalidateRect(hPalWin
, NULL
, FALSE
);
905 case IDM_COLORSMODERNPALETTE
:
907 CopyMemory(palColors
, modernPalColors
, sizeof(palColors
));
908 InvalidateRect(hPalWin
, NULL
, FALSE
);
910 case IDM_COLORSOLDPALETTE
:
912 CopyMemory(palColors
, oldPalColors
, sizeof(palColors
));
913 InvalidateRect(hPalWin
, NULL
, FALSE
);
915 case IDM_IMAGEINVERTCOLORS
:
919 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
920 InvertRect(hDrawingDC
, &tempRect
);
921 InvalidateRect(hImageArea
, NULL
, FALSE
);
924 case IDM_IMAGEDELETEIMAGE
:
926 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
927 InvalidateRect(hImageArea
, NULL
, FALSE
);
929 case IDM_IMAGEROTATEMIRROR
:
930 switch (mirrorRotateDlg())
932 case 1: /* flip horizontally */
933 if (IsWindowVisible(hSelection
))
935 SelectObject(hSelDC
, hSelMask
);
936 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
937 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
938 SelectObject(hSelDC
, hSelBm
);
939 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
940 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
941 /* force refresh of selection contents, used also in case 2 and case 4 */
942 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
943 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
944 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
949 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
950 imgXRes
, imgYRes
, SRCCOPY
);
951 InvalidateRect(hImageArea
, NULL
, FALSE
);
954 case 2: /* flip vertically */
955 if (IsWindowVisible(hSelection
))
957 SelectObject(hSelDC
, hSelMask
);
958 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
959 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
960 SelectObject(hSelDC
, hSelBm
);
961 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
962 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
963 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
964 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
965 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
970 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
971 imgXRes
, imgYRes
, SRCCOPY
);
972 InvalidateRect(hImageArea
, NULL
, FALSE
);
975 case 3: /* rotate 90 degrees */
977 case 4: /* rotate 180 degrees */
978 if (IsWindowVisible(hSelection
))
980 SelectObject(hSelDC
, hSelMask
);
981 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
982 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
983 SelectObject(hSelDC
, hSelBm
);
984 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
985 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
986 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
987 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
988 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
993 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
994 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
995 InvalidateRect(hImageArea
, NULL
, FALSE
);
998 case 5: /* rotate 270 degrees */
1002 case IDM_IMAGEATTRIBUTES
:
1004 if (attributesDlg())
1006 cropReversible(widthSetInDlg
, heightSetInDlg
, 0, 0);
1007 updateCanvasAndScrollbars();
1011 case IDM_IMAGESTRETCHSKEW
:
1013 if (changeSizeDlg())
1015 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
1016 imgXRes
* stretchSkew
.percentage
.x
/ 100,
1017 imgYRes
* stretchSkew
.percentage
.y
/ 100, 0));
1018 updateCanvasAndScrollbars();
1022 case IDM_IMAGEDRAWOPAQUE
:
1023 transpBg
= 1 - transpBg
;
1024 InvalidateRect(hToolSettings
, NULL
, TRUE
);
1027 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
1028 updateCanvasAndScrollbars();
1031 case IDM_VIEWTOOLBOX
:
1032 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
1033 alignChildrenToMainWindow();
1035 case IDM_VIEWCOLORPALETTE
:
1036 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
1037 alignChildrenToMainWindow();
1039 case IDM_VIEWSTATUSBAR
:
1040 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
1041 alignChildrenToMainWindow();
1044 case IDM_VIEWSHOWGRID
:
1045 showGrid
= !showGrid
;
1046 InvalidateRect(hImageArea
, NULL
, FALSE
);
1048 case IDM_VIEWSHOWMINIATURE
:
1049 showMiniature
= !showMiniature
;
1050 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
1053 case IDM_VIEWZOOM125
:
1056 case IDM_VIEWZOOM25
:
1059 case IDM_VIEWZOOM50
:
1062 case IDM_VIEWZOOM100
:
1065 case IDM_VIEWZOOM200
:
1068 case IDM_VIEWZOOM400
:
1071 case IDM_VIEWZOOM800
:
1125 return DefWindowProc(hwnd
, message
, wParam
, lParam
);