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 *********************************************************/
17 /* FUNCTIONS ********************************************************/
22 ShowWindow(hSelection
, SW_HIDE
);
24 pointSP
= 0; // resets the point-buffer of the polygon and bezier functions
25 InvalidateRect(hToolSettings
, NULL
, TRUE
);
26 ShowWindow(hTrackbarZoom
, (tool
== 6) ? SW_SHOW
: SW_HIDE
);
30 updateCanvasAndScrollbars()
32 ShowWindow(hSelection
, SW_HIDE
);
33 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
34 InvalidateRect(hScrollbox
, NULL
, TRUE
);
35 InvalidateRect(hImageArea
, NULL
, FALSE
);
37 SetScrollPos(hScrollbox
, SB_HORZ
, 0, TRUE
);
38 SetScrollPos(hScrollbox
, SB_VERT
, 0, TRUE
);
42 zoomTo(int newZoom
, int mouseX
, int mouseY
)
45 int tempZoom
= newZoom
;
47 long clientRectScrollbox
[4];
48 long clientRectImageArea
[4];
50 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
51 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
52 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * newZoom
/ zoom
);
53 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * newZoom
/ zoom
);
54 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2)) * newZoom
/ zoom
;
55 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2)) * newZoom
/ zoom
;
59 ShowWindow(hSelection
, SW_HIDE
);
60 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
61 InvalidateRect(hScrollbox
, NULL
, TRUE
);
62 InvalidateRect(hImageArea
, NULL
, FALSE
);
64 SendMessage(hScrollbox
, WM_HSCROLL
, SB_THUMBPOSITION
| (x
<< 16), 0);
65 SendMessage(hScrollbox
, WM_VSCROLL
, SB_THUMBPOSITION
| (y
<< 16), 0);
67 while (tempZoom
> 125)
70 tempZoom
= tempZoom
>> 1;
72 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) tbPos
);
76 drawZoomFrame(int mouseX
, int mouseY
)
84 long clientRectScrollbox
[4];
85 long clientRectImageArea
[4];
87 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
88 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
89 w
= clientRectImageArea
[2] * clientRectScrollbox
[2] / (clientRectImageArea
[2] * 2);
90 h
= clientRectImageArea
[3] * clientRectScrollbox
[3] / (clientRectImageArea
[3] * 2);
91 x
= max(0, min(clientRectImageArea
[2] - w
, mouseX
- w
/ 2));
92 y
= max(0, min(clientRectImageArea
[3] - h
, mouseY
- h
/ 2));
94 hdc
= GetDC(hImageArea
);
95 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, 0));
96 logbrush
.lbStyle
= BS_HOLLOW
;
97 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
98 rop
= SetROP2(hdc
, R2_NOT
);
99 Rectangle(hdc
, x
, y
, x
+ w
, y
+ h
);
101 DeleteObject(SelectObject(hdc
, oldBrush
));
102 DeleteObject(SelectObject(hdc
, oldPen
));
103 ReleaseDC(hImageArea
, hdc
);
107 alignChildrenToMainWindow()
111 GetClientRect(hMainWnd
, &clientRect
);
113 if (IsWindowVisible(hToolBoxContainer
))
116 w
= clientRect
.right
- 56;
121 w
= clientRect
.right
;
123 if (IsWindowVisible(hPalWin
))
126 h
= clientRect
.bottom
- 49;
131 h
= clientRect
.bottom
- 3;
134 MoveWindow(hScrollbox
, x
, y
, w
, IsWindowVisible(hStatusBar
) ? h
- 23 : h
, TRUE
);
135 MoveWindow(hPalWin
, x
, 9, 255, 32, TRUE
);
139 saveImage(BOOL overwrite
)
141 if (isAFile
&& overwrite
)
143 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
147 else if (GetSaveFileName(&sfn
) != 0)
151 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
153 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
154 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
155 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
156 _stprintf(tempstr
, resstr
, filename
);
157 SetWindowText(hMainWnd
, tempstr
);
164 UpdateApplicationProperties(HBITMAP bitmap
, LPTSTR newfilename
, LPTSTR newfilepathname
)
168 insertReversible(bitmap
);
169 updateCanvasAndScrollbars();
170 CopyMemory(filename
, newfilename
, sizeof(filename
));
171 CopyMemory(filepathname
, newfilepathname
, sizeof(filepathname
));
172 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
173 _stprintf(tempstr
, resstr
, filename
);
174 SetWindowText(hMainWnd
, tempstr
);
180 InsertSelectionFromHBITMAP(HBITMAP bitmap
, HWND window
)
182 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
183 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
184 SendMessage(window
, WM_COMMAND
, ID_RECTSEL
, 0);
186 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(bitmap
,
190 rectSel_src
[0] = rectSel_src
[1] = rectSel_src
[2] = rectSel_src
[3] = 0;
191 rectSel_dest
[0] = rectSel_dest
[1] = 0;
192 rectSel_dest
[2] = GetDIBWidth(hSelBm
);
193 rectSel_dest
[3] = GetDIBHeight(hSelBm
);
194 BitBlt(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2], rectSel_dest
[3],
195 hSelDC
, 0, 0, SRCCOPY
);
197 ShowWindow(hSelection
, SW_SHOW
);
203 WindowProcedure(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
205 switch (message
) /* handle the messages */
210 TCHAR droppedfile
[MAX_PATH
];
211 HBITMAP bmNew
= NULL
;
212 drophandle
= (HDROP
)wParam
;
213 DragQueryFile(drophandle
, 0, droppedfile
, SIZEOF(droppedfile
));
214 DragFinish(drophandle
);
215 LoadDIBFromFile(&bmNew
, droppedfile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
219 pathend
= _tcsrchr(droppedfile
, '\\');
221 UpdateApplicationProperties(bmNew
, pathend
, pathend
);
232 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
236 if (hwnd
== hwndMiniature
)
238 ShowWindow(hwndMiniature
, SW_HIDE
);
239 showMiniature
= FALSE
;
244 TCHAR programname
[20];
245 TCHAR saveprompttext
[100];
247 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
248 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
249 _stprintf(temptext
, saveprompttext
, filename
);
250 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
268 case WM_INITMENUPOPUP
:
274 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
275 MF_ENABLED
| MF_BYCOMMAND
);
276 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
277 MF_ENABLED
| MF_BYCOMMAND
);
278 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
279 MF_ENABLED
| MF_BYCOMMAND
);
283 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERPLANE
,
284 MF_GRAYED
| MF_BYCOMMAND
);
285 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERCENTERED
,
286 MF_GRAYED
| MF_BYCOMMAND
);
287 EnableMenuItem(GetMenu(hMainWnd
), IDM_FILEASWALLPAPERSTRETCHED
,
288 MF_GRAYED
| MF_BYCOMMAND
);
292 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITUNDO
,
293 (undoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
294 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITREDO
,
295 (redoSteps
> 0) ? (MF_ENABLED
| MF_BYCOMMAND
) : (MF_GRAYED
| MF_BYCOMMAND
));
296 if (IsWindowVisible(hSelection
))
298 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_ENABLED
| MF_BYCOMMAND
);
299 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_ENABLED
| MF_BYCOMMAND
);
300 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
301 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_ENABLED
| MF_BYCOMMAND
);
302 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_ENABLED
| MF_BYCOMMAND
);
306 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCUT
, MF_GRAYED
| MF_BYCOMMAND
);
307 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPY
, MF_GRAYED
| MF_BYCOMMAND
);
308 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITDELETESELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
309 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITINVERTSELECTION
, MF_GRAYED
| MF_BYCOMMAND
);
310 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITCOPYTO
, MF_GRAYED
| MF_BYCOMMAND
);
312 OpenClipboard(hMainWnd
);
313 if (GetClipboardData(CF_BITMAP
) != NULL
)
314 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_ENABLED
| MF_BYCOMMAND
);
316 EnableMenuItem(GetMenu(hMainWnd
), IDM_EDITPASTE
, MF_GRAYED
| MF_BYCOMMAND
);
320 if (IsWindowVisible(hSelection
))
321 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_ENABLED
| MF_BYCOMMAND
);
323 EnableMenuItem(GetMenu(hMainWnd
), IDM_IMAGECROP
, MF_GRAYED
| MF_BYCOMMAND
);
324 CheckMenuItem(GetMenu(hMainWnd
), IDM_IMAGEDRAWOPAQUE
, (transpBg
== 0) ?
325 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
328 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWTOOLBOX
,
329 IsWindowVisible(hToolBoxContainer
) ?
330 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
331 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWCOLORPALETTE
,
332 IsWindowVisible(hPalWin
) ?
333 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
334 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSTATUSBAR
,
335 IsWindowVisible(hStatusBar
) ?
336 (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
338 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWGRID
,
339 showGrid
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
340 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWSHOWMINIATURE
,
341 showMiniature
? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
343 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM125
,
344 (zoom
== 125) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
345 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM25
,
346 (zoom
== 250) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
347 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM50
,
348 (zoom
== 500) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
349 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM100
,
350 (zoom
== 1000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
351 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM200
,
352 (zoom
== 2000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
353 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM400
,
354 (zoom
== 4000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
355 CheckMenuItem(GetMenu(hMainWnd
), IDM_VIEWZOOM800
,
356 (zoom
== 8000) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
358 CheckMenuItem(GetMenu(hMainWnd
), IDM_COLORSMODERNPALETTE
,
359 (selectedPalette
== 1) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
360 CheckMenuItem(GetMenu(hMainWnd
), IDM_COLORSOLDPALETTE
,
361 (selectedPalette
== 2) ? (MF_CHECKED
| MF_BYCOMMAND
) : (MF_UNCHECKED
| MF_BYCOMMAND
));
365 if (hwnd
== hMainWnd
)
367 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
368 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
369 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (LPARAM
)&test
);
370 alignChildrenToMainWindow();
371 InvalidateRect(hwnd
, NULL
, TRUE
);
373 if (hwnd
== hImageArea
)
375 MoveWindow(hSizeboxLeftTop
,
378 MoveWindow(hSizeboxCenterTop
,
379 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
381 MoveWindow(hSizeboxRightTop
,
382 imgXRes
* zoom
/ 1000 + 3,
384 MoveWindow(hSizeboxLeftCenter
,
386 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
387 MoveWindow(hSizeboxRightCenter
,
388 imgXRes
* zoom
/ 1000 + 3,
389 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
390 MoveWindow(hSizeboxLeftBottom
,
392 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
393 MoveWindow(hSizeboxCenterBottom
,
394 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
395 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
396 MoveWindow(hSizeboxRightBottom
,
397 imgXRes
* zoom
/ 1000 + 3,
398 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
400 if ((hwnd
== hImageArea
) || (hwnd
== hScrollbox
))
402 long clientRectScrollbox
[4];
403 long clientRectImageArea
[4];
405 GetClientRect(hScrollbox
, (LPRECT
) &clientRectScrollbox
);
406 GetClientRect(hImageArea
, (LPRECT
) &clientRectImageArea
);
407 si
.cbSize
= sizeof(SCROLLINFO
);
408 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
409 si
.nMax
= clientRectImageArea
[2] + 6 - 1;
411 si
.nPage
= clientRectScrollbox
[2];
412 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
413 GetClientRect(hScrollbox
, (LPRECT
) clientRectScrollbox
);
414 si
.nMax
= clientRectImageArea
[3] + 6 - 1;
415 si
.nPage
= clientRectScrollbox
[3];
416 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
417 MoveWindow(hScrlClient
,
418 -GetScrollPos(hScrollbox
, SB_HORZ
), -GetScrollPos(hScrollbox
, SB_VERT
),
419 max(clientRectImageArea
[2] + 6, clientRectScrollbox
[2]),
420 max(clientRectImageArea
[3] + 6, clientRectScrollbox
[3]), TRUE
);
425 if (hwnd
== hScrollbox
)
428 si
.cbSize
= sizeof(SCROLLINFO
);
430 GetScrollInfo(hScrollbox
, SB_HORZ
, &si
);
431 switch (LOWORD(wParam
))
434 case SB_THUMBPOSITION
:
435 si
.nPos
= HIWORD(wParam
);
450 SetScrollInfo(hScrollbox
, SB_HORZ
, &si
, TRUE
);
451 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
452 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
453 imgYRes
* zoom
/ 1000 + 6, TRUE
);
458 if (hwnd
== hScrollbox
)
461 si
.cbSize
= sizeof(SCROLLINFO
);
463 GetScrollInfo(hScrollbox
, SB_VERT
, &si
);
464 switch (LOWORD(wParam
))
467 case SB_THUMBPOSITION
:
468 si
.nPos
= HIWORD(wParam
);
483 SetScrollInfo(hScrollbox
, SB_VERT
, &si
, TRUE
);
484 MoveWindow(hScrlClient
, -GetScrollPos(hScrollbox
, SB_HORZ
),
485 -GetScrollPos(hScrollbox
, SB_VERT
), imgXRes
* zoom
/ 1000 + 6,
486 imgYRes
* zoom
/ 1000 + 6, TRUE
);
490 case WM_GETMINMAXINFO
:
491 if (hwnd
== hMainWnd
)
493 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
494 mm
->ptMinTrackSize
.x
= 330;
495 mm
->ptMinTrackSize
.y
= 430;
500 DefWindowProc(hwnd
, message
, wParam
, lParam
);
501 if (hwnd
== hImageArea
)
503 HDC hdc
= GetDC(hImageArea
);
504 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
506 if (showGrid
&& (zoom
>= 4000))
508 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
510 for(counter
= 0; counter
<= imgYRes
; counter
++)
512 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
513 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
515 for(counter
= 0; counter
<= imgXRes
; counter
++)
517 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
518 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
520 DeleteObject(SelectObject(hdc
, oldPen
));
522 ReleaseDC(hImageArea
, hdc
);
523 InvalidateRect(hSelection
, NULL
, FALSE
);
524 InvalidateRect(hwndMiniature
, NULL
, FALSE
);
526 else if (hwnd
== hwndMiniature
)
530 GetClientRect(hwndMiniature
, &mclient
);
531 hdc
= GetDC(hwndMiniature
);
532 StretchBlt(hdc
, 0, 0, mclient
.right
, mclient
.bottom
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
533 ReleaseDC(hwndMiniature
, hdc
);
537 // mouse events used for drawing
540 if (hwnd
== hImageArea
)
548 SetCursor(hCurColor
);
557 SetCursor(hCurAirbrush
);
560 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
564 DefWindowProc(hwnd
, message
, wParam
, lParam
);
568 if (hwnd
== hImageArea
)
570 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
572 SetCapture(hImageArea
);
574 startPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
579 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
582 InvalidateRect(hImageArea
, NULL
, FALSE
);
583 if ((activeTool
== TOOL_ZOOM
) && (zoom
< 8000))
584 zoomTo(zoom
* 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
589 if (hwnd
== hImageArea
)
591 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
593 SetCapture(hImageArea
);
595 startPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
600 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
603 InvalidateRect(hImageArea
, NULL
, FALSE
);
604 if ((activeTool
== TOOL_ZOOM
) && (zoom
> 125))
605 zoomTo(zoom
/ 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
610 if ((hwnd
== hImageArea
) && drawing
)
614 endPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
616 InvalidateRect(hImageArea
, NULL
, FALSE
);
617 if (activeTool
== TOOL_COLOR
)
620 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
621 if (tempColor
!= CLR_INVALID
)
623 InvalidateRect(hPalWin
, NULL
, FALSE
);
625 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
630 if ((hwnd
== hImageArea
) && drawing
)
634 endPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
636 InvalidateRect(hImageArea
, NULL
, FALSE
);
637 if (activeTool
== TOOL_COLOR
)
640 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
641 if (tempColor
!= CLR_INVALID
)
643 InvalidateRect(hPalWin
, NULL
, FALSE
);
645 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
650 if (wParam
== VK_ESCAPE
)
655 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
657 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
658 whilePaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
659 endPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
660 ShowWindow(hSelection
, SW_HIDE
);
663 /* FIXME: also cancel current drawing underway */
668 if (hwnd
== hImageArea
)
670 LONG xNow
= GET_X_LPARAM(lParam
) * 1000 / zoom
;
671 LONG yNow
= GET_Y_LPARAM(lParam
) * 1000 / zoom
;
672 if ((!drawing
) || (activeTool
<= TOOL_AIRBRUSH
))
676 if (activeTool
== TOOL_ZOOM
)
678 InvalidateRect(hImageArea
, NULL
, FALSE
);
679 UpdateWindow(hImageArea
);
680 drawZoomFrame(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
683 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
684 tme
.dwFlags
= TME_LEAVE
;
685 tme
.hwndTrack
= hImageArea
;
687 TrackMouseEvent(&tme
);
692 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
693 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
698 /* values displayed in statusbar */
699 LONG xRel
= xNow
- start
.x
;
700 LONG yRel
= yNow
- start
.y
;
701 /* freesel, rectsel and text tools always show numbers limited to fit into image area */
702 if ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_TEXT
))
705 xRel
= (xNow
< 0) ? -start
.x
: xRel
;
706 else if (xNow
> imgXRes
)
707 xRel
= imgXRes
-start
.x
;
709 yRel
= (yNow
< 0) ? -start
.y
: yRel
;
710 else if (yNow
> imgYRes
)
711 yRel
= imgYRes
-start
.y
;
713 /* rectsel and shape tools always show non-negative numbers when drawing */
714 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_SHAPE
))
721 /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
731 _stprintf(coordStr
, _T("%d, %d"), xNow
, yNow
);
732 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
736 if ((wParam
& MK_LBUTTON
) != 0)
738 whilePaintingL(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
739 InvalidateRect(hImageArea
, NULL
, FALSE
);
740 if ((activeTool
>= TOOL_TEXT
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
743 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
745 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
746 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
749 if ((wParam
& MK_RBUTTON
) != 0)
751 whilePaintingR(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
752 InvalidateRect(hImageArea
, NULL
, FALSE
);
753 if (activeTool
>= TOOL_TEXT
)
756 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
758 _stprintf(sizeStr
, _T("%d x %d"), xRel
, yRel
);
759 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
767 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
768 if (activeTool
== TOOL_ZOOM
)
769 InvalidateRect(hImageArea
, NULL
, FALSE
);
772 // menu and button events
774 case WM_SYSCOLORCHANGE
:
776 /* Redirect message to common controls */
777 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
778 SendMessage(hToolbar
, WM_SYSCOLORCHANGE
, 0, 0);
783 switch (LOWORD(wParam
))
787 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
788 TCHAR infotitle
[100];
790 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
791 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
792 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
793 DeleteObject(paintIcon
);
796 case IDM_HELPHELPTOPICS
:
797 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
800 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
807 TCHAR programname
[20];
808 TCHAR saveprompttext
[100];
810 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
811 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
812 _stprintf(temptext
, saveprompttext
, filename
);
813 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
826 if (reset
&& imageSaved
)
828 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
829 InvalidateRect(hImageArea
, NULL
, FALSE
);
830 updateCanvasAndScrollbars();
836 if (GetOpenFileName(&ofn
) != 0)
838 HBITMAP bmNew
= NULL
;
839 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
842 UpdateApplicationProperties(bmNew
, ofn
.lpstrFileTitle
, ofn
.lpstrFileTitle
);
852 case IDM_FILEASWALLPAPERPLANE
:
853 SetWallpaper(filepathname
, 1, 1);
855 case IDM_FILEASWALLPAPERCENTERED
:
856 SetWallpaper(filepathname
, 1, 0);
858 case IDM_FILEASWALLPAPERSTRETCHED
:
859 SetWallpaper(filepathname
, 2, 0);
863 InvalidateRect(hImageArea
, NULL
, FALSE
);
867 InvalidateRect(hImageArea
, NULL
, FALSE
);
870 OpenClipboard(hMainWnd
);
872 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
877 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITCOPY
, 0);
878 /* Delete selection */
879 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITDELETESELECTION
, 0);
882 OpenClipboard(hMainWnd
);
883 if (GetClipboardData(CF_BITMAP
) != NULL
)
885 InsertSelectionFromHBITMAP(GetClipboardData(CF_BITMAP
), hwnd
);
889 case IDM_EDITDELETESELECTION
:
891 /* remove selection window and already painted content using undo(),
892 paint Rect for rectangular selections and Poly for freeform selections */
894 if (activeTool
== TOOL_RECTSEL
)
897 Rect(hDrawingDC
, rectSel_dest
[0], rectSel_dest
[1], rectSel_dest
[2] + rectSel_dest
[0],
898 rectSel_dest
[3] + rectSel_dest
[1], bgColor
, bgColor
, 0, TRUE
);
900 if (activeTool
== TOOL_FREESEL
)
903 Poly(hDrawingDC
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
907 case IDM_EDITSELECTALL
:
909 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
910 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
911 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
912 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
913 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
914 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
918 if (GetSaveFileName(&ofn
) != 0)
919 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
921 case IDM_EDITPASTEFROM
:
922 if (GetOpenFileName(&ofn
) != 0)
924 HBITMAP bmNew
= NULL
;
925 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
928 InsertSelectionFromHBITMAP(bmNew
, hwnd
);
933 case IDM_COLORSEDITPALETTE
:
934 if (ChooseColor(&choosecolor
))
936 fgColor
= choosecolor
.rgbResult
;
937 InvalidateRect(hPalWin
, NULL
, FALSE
);
940 case IDM_COLORSMODERNPALETTE
:
942 CopyMemory(palColors
, modernPalColors
, sizeof(palColors
));
943 InvalidateRect(hPalWin
, NULL
, FALSE
);
945 case IDM_COLORSOLDPALETTE
:
947 CopyMemory(palColors
, oldPalColors
, sizeof(palColors
));
948 InvalidateRect(hPalWin
, NULL
, FALSE
);
950 case IDM_IMAGEINVERTCOLORS
:
954 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
955 InvertRect(hDrawingDC
, &tempRect
);
956 InvalidateRect(hImageArea
, NULL
, FALSE
);
959 case IDM_IMAGEDELETEIMAGE
:
961 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
962 InvalidateRect(hImageArea
, NULL
, FALSE
);
964 case IDM_IMAGEROTATEMIRROR
:
965 switch (mirrorRotateDlg())
967 case 1: /* flip horizontally */
968 if (IsWindowVisible(hSelection
))
970 SelectObject(hSelDC
, hSelMask
);
971 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
972 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
973 SelectObject(hSelDC
, hSelBm
);
974 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, 0, -rectSel_dest
[2], rectSel_dest
[3], hSelDC
,
975 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
976 /* force refresh of selection contents, used also in case 2 and case 4 */
977 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
978 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
979 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
984 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
985 imgXRes
, imgYRes
, SRCCOPY
);
986 InvalidateRect(hImageArea
, NULL
, FALSE
);
989 case 2: /* flip vertically */
990 if (IsWindowVisible(hSelection
))
992 SelectObject(hSelDC
, hSelMask
);
993 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
994 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
995 SelectObject(hSelDC
, hSelBm
);
996 StretchBlt(hSelDC
, 0, rectSel_dest
[3] - 1, rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
997 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
998 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
999 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
1000 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
1005 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
1006 imgXRes
, imgYRes
, SRCCOPY
);
1007 InvalidateRect(hImageArea
, NULL
, FALSE
);
1010 case 3: /* rotate 90 degrees */
1012 case 4: /* rotate 180 degrees */
1013 if (IsWindowVisible(hSelection
))
1015 SelectObject(hSelDC
, hSelMask
);
1016 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
1017 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
1018 SelectObject(hSelDC
, hSelBm
);
1019 StretchBlt(hSelDC
, rectSel_dest
[2] - 1, rectSel_dest
[3] - 1, -rectSel_dest
[2], -rectSel_dest
[3], hSelDC
,
1020 0, 0, rectSel_dest
[2], rectSel_dest
[3], SRCCOPY
);
1021 SendMessage(hSelection
, WM_LBUTTONDOWN
, 0, 0);
1022 SendMessage(hSelection
, WM_MOUSEMOVE
, 0, 0);
1023 SendMessage(hSelection
, WM_LBUTTONUP
, 0, 0);
1028 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
1029 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
1030 InvalidateRect(hImageArea
, NULL
, FALSE
);
1033 case 5: /* rotate 270 degrees */
1037 case IDM_IMAGEATTRIBUTES
:
1039 if (attributesDlg())
1041 cropReversible(widthSetInDlg
, heightSetInDlg
, 0, 0);
1042 updateCanvasAndScrollbars();
1046 case IDM_IMAGESTRETCHSKEW
:
1048 if (changeSizeDlg())
1050 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
1051 imgXRes
* stretchSkew
.percentage
.x
/ 100,
1052 imgYRes
* stretchSkew
.percentage
.y
/ 100, 0));
1053 updateCanvasAndScrollbars();
1057 case IDM_IMAGEDRAWOPAQUE
:
1058 transpBg
= 1 - transpBg
;
1059 InvalidateRect(hToolSettings
, NULL
, TRUE
);
1062 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
1063 updateCanvasAndScrollbars();
1066 case IDM_VIEWTOOLBOX
:
1067 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
1068 alignChildrenToMainWindow();
1070 case IDM_VIEWCOLORPALETTE
:
1071 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
1072 alignChildrenToMainWindow();
1074 case IDM_VIEWSTATUSBAR
:
1075 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
1076 alignChildrenToMainWindow();
1079 case IDM_VIEWSHOWGRID
:
1080 showGrid
= !showGrid
;
1081 InvalidateRect(hImageArea
, NULL
, FALSE
);
1083 case IDM_VIEWSHOWMINIATURE
:
1084 showMiniature
= !showMiniature
;
1085 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
1088 case IDM_VIEWZOOM125
:
1091 case IDM_VIEWZOOM25
:
1094 case IDM_VIEWZOOM50
:
1097 case IDM_VIEWZOOM100
:
1100 case IDM_VIEWZOOM200
:
1103 case IDM_VIEWZOOM400
:
1106 case IDM_VIEWZOOM800
:
1160 return DefWindowProc(hwnd
, message
, wParam
, lParam
);