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 #include "scrollbox.h"
19 /* FUNCTIONS ********************************************************/
25 /* initializing and registering the window class used for the main window */
26 wclMain
.hInstance
= hProgInstance
;
27 wclMain
.lpszClassName
= _T("MainWindow");
28 wclMain
.lpfnWndProc
= MainWindowProcedure
;
29 wclMain
.style
= CS_DBLCLKS
;
30 wclMain
.cbSize
= sizeof(WNDCLASSEX
);
31 wclMain
.hIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
32 wclMain
.hIconSm
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
33 wclMain
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
34 wclMain
.lpszMenuName
= NULL
;
35 wclMain
.cbClsExtra
= 0;
36 wclMain
.cbWndExtra
= 0;
37 wclMain
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
38 RegisterClassEx (&wclMain
);
44 ShowWindow(hSelection
, SW_HIDE
);
46 pointSP
= 0; // resets the point-buffer of the polygon and bezier functions
47 InvalidateRect(hToolSettings
, NULL
, TRUE
);
48 ShowWindow(hTrackbarZoom
, (tool
== TOOL_ZOOM
) ? SW_SHOW
: SW_HIDE
);
49 ShowWindow(hwndTextEdit
, (tool
== TOOL_TEXT
) ? SW_SHOW
: SW_HIDE
);
53 updateCanvasAndScrollbars()
55 ShowWindow(hSelection
, SW_HIDE
);
56 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
57 InvalidateRect(hScrollbox
, NULL
, TRUE
);
58 InvalidateRect(hImageArea
, NULL
, FALSE
);
60 SetScrollPos(hScrollbox
, SB_HORZ
, 0, TRUE
);
61 SetScrollPos(hScrollbox
, SB_VERT
, 0, TRUE
);
65 zoomTo(int newZoom
, int mouseX
, int mouseY
)
68 int tempZoom
= newZoom
;
70 RECT clientRectScrollbox
;
71 RECT clientRectImageArea
;
73 GetClientRect(hScrollbox
, &clientRectScrollbox
);
74 GetClientRect(hImageArea
, &clientRectImageArea
);
75 w
= clientRectImageArea
.right
* clientRectScrollbox
.right
/ (clientRectImageArea
.right
* newZoom
/ zoom
);
76 h
= clientRectImageArea
.bottom
* clientRectScrollbox
.bottom
/ (clientRectImageArea
.bottom
* newZoom
/ zoom
);
77 x
= max(0, min(clientRectImageArea
.right
- w
, mouseX
- w
/ 2)) * newZoom
/ zoom
;
78 y
= max(0, min(clientRectImageArea
.bottom
- h
, mouseY
- h
/ 2)) * newZoom
/ zoom
;
82 ShowWindow(hSelection
, SW_HIDE
);
83 MoveWindow(hImageArea
, 3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
84 InvalidateRect(hScrollbox
, NULL
, TRUE
);
85 InvalidateRect(hImageArea
, NULL
, FALSE
);
87 SendMessage(hScrollbox
, WM_HSCROLL
, SB_THUMBPOSITION
| (x
<< 16), 0);
88 SendMessage(hScrollbox
, WM_VSCROLL
, SB_THUMBPOSITION
| (y
<< 16), 0);
90 while (tempZoom
> 125)
93 tempZoom
= tempZoom
>> 1;
95 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) tbPos
);
99 drawZoomFrame(int mouseX
, int mouseY
)
107 RECT clientRectScrollbox
;
108 RECT clientRectImageArea
;
110 GetClientRect(hScrollbox
, &clientRectScrollbox
);
111 GetClientRect(hImageArea
, &clientRectImageArea
);
112 w
= clientRectImageArea
.right
* clientRectScrollbox
.right
/ (clientRectImageArea
.right
* 2);
113 h
= clientRectImageArea
.bottom
* clientRectScrollbox
.bottom
/ (clientRectImageArea
.bottom
* 2);
114 x
= max(0, min(clientRectImageArea
.right
- w
, mouseX
- w
/ 2));
115 y
= max(0, min(clientRectImageArea
.bottom
- h
, mouseY
- h
/ 2));
117 hdc
= GetDC(hImageArea
);
118 oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, 0));
119 logbrush
.lbStyle
= BS_HOLLOW
;
120 oldBrush
= SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
121 rop
= SetROP2(hdc
, R2_NOT
);
122 Rectangle(hdc
, x
, y
, x
+ w
, y
+ h
);
124 DeleteObject(SelectObject(hdc
, oldBrush
));
125 DeleteObject(SelectObject(hdc
, oldPen
));
126 ReleaseDC(hImageArea
, hdc
);
130 alignChildrenToMainWindow()
134 GetClientRect(hMainWnd
, &clientRect
);
136 if (IsWindowVisible(hToolBoxContainer
))
139 w
= clientRect
.right
- 56;
144 w
= clientRect
.right
;
146 if (IsWindowVisible(hPalWin
))
149 h
= clientRect
.bottom
- 49;
154 h
= clientRect
.bottom
- 3;
157 MoveWindow(hScrollbox
, x
, y
, w
, IsWindowVisible(hStatusBar
) ? h
- 23 : h
, TRUE
);
158 MoveWindow(hPalWin
, x
, 9, 255, 32, TRUE
);
162 saveImage(BOOL overwrite
)
164 if (isAFile
&& overwrite
)
166 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
170 else if (GetSaveFileName(&sfn
) != 0)
174 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
176 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
177 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
178 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
179 _stprintf(tempstr
, resstr
, filename
);
180 SetWindowText(hMainWnd
, tempstr
);
187 UpdateApplicationProperties(HBITMAP bitmap
, LPTSTR newfilename
, LPTSTR newfilepathname
)
191 insertReversible(bitmap
);
192 updateCanvasAndScrollbars();
193 CopyMemory(filename
, newfilename
, sizeof(filename
));
194 CopyMemory(filepathname
, newfilepathname
, sizeof(filepathname
));
195 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
196 _stprintf(tempstr
, resstr
, filename
);
197 SetWindowText(hMainWnd
, tempstr
);
203 InsertSelectionFromHBITMAP(HBITMAP bitmap
, HWND window
)
208 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
209 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
210 SendMessage(window
, WM_COMMAND
, ID_RECTSEL
, 0);
212 DeleteObject(SelectObject(hSelDC
, hSelBm
= CopyImage(bitmap
,
216 SetRectEmpty(&rectSel_src
);
217 rectSel_dest
.left
= rectSel_dest
.top
= 0;
218 rectSel_dest
.right
= rectSel_dest
.left
+ GetDIBWidth(hSelBm
);
219 rectSel_dest
.bottom
= rectSel_dest
.top
+ GetDIBHeight(hSelBm
);
221 hTempDC
= CreateCompatibleDC(hSelDC
);
222 hTempMask
= CreateBitmap(RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), 1, 1, NULL
);
223 SelectObject(hTempDC
, hTempMask
);
224 Rect(hTempDC
, rectSel_dest
.left
, rectSel_dest
.top
, rectSel_dest
.right
, rectSel_dest
.bottom
, 0x00ffffff, 0x00ffffff, 1, 1);
225 DeleteObject(hSelMask
);
226 hSelMask
= hTempMask
;
230 ShowWindow(hSelection
, SW_SHOW
);
231 ForceRefreshSelectionContents();
237 MainWindowProcedure(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
239 switch (message
) /* handle the messages */
244 TCHAR droppedfile
[MAX_PATH
];
245 HBITMAP bmNew
= NULL
;
246 drophandle
= (HDROP
)wParam
;
247 DragQueryFile(drophandle
, 0, droppedfile
, SIZEOF(droppedfile
));
248 DragFinish(drophandle
);
249 LoadDIBFromFile(&bmNew
, droppedfile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
253 pathend
= _tcsrchr(droppedfile
, '\\');
255 UpdateApplicationProperties(bmNew
, pathend
, pathend
);
266 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
270 if (hwnd
== hwndMiniature
)
272 ShowWindow(hwndMiniature
, SW_HIDE
);
273 showMiniature
= FALSE
;
278 TCHAR programname
[20];
279 TCHAR saveprompttext
[100];
281 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
282 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
283 _stprintf(temptext
, saveprompttext
, filename
);
284 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
302 case WM_INITMENUPOPUP
:
304 HMENU menu
= GetMenu(hMainWnd
);
305 BOOL trueSelection
= (IsWindowVisible(hSelection
) && ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
)));
308 case 0: /* File menu */
309 EnableMenuItem(menu
, IDM_FILEASWALLPAPERPLANE
, ENABLED_IF(isAFile
));
310 EnableMenuItem(menu
, IDM_FILEASWALLPAPERCENTERED
, ENABLED_IF(isAFile
));
311 EnableMenuItem(menu
, IDM_FILEASWALLPAPERSTRETCHED
, ENABLED_IF(isAFile
));
313 case 1: /* Edit menu */
314 EnableMenuItem(menu
, IDM_EDITUNDO
, ENABLED_IF(undoSteps
> 0));
315 EnableMenuItem(menu
, IDM_EDITREDO
, ENABLED_IF(redoSteps
> 0));
316 EnableMenuItem(menu
, IDM_EDITCUT
, ENABLED_IF(trueSelection
));
317 EnableMenuItem(menu
, IDM_EDITCOPY
, ENABLED_IF(trueSelection
));
318 EnableMenuItem(menu
, IDM_EDITDELETESELECTION
, ENABLED_IF(trueSelection
));
319 EnableMenuItem(menu
, IDM_EDITINVERTSELECTION
, ENABLED_IF(trueSelection
));
320 EnableMenuItem(menu
, IDM_EDITCOPYTO
, ENABLED_IF(trueSelection
));
321 OpenClipboard(hMainWnd
);
322 EnableMenuItem(menu
, IDM_EDITPASTE
, ENABLED_IF(GetClipboardData(CF_BITMAP
) != NULL
));
325 case 2: /* View menu */
326 CheckMenuItem(menu
, IDM_VIEWTOOLBOX
, CHECKED_IF(IsWindowVisible(hToolBoxContainer
)));
327 CheckMenuItem(menu
, IDM_VIEWCOLORPALETTE
, CHECKED_IF(IsWindowVisible(hPalWin
)));
328 CheckMenuItem(menu
, IDM_VIEWSTATUSBAR
, CHECKED_IF(IsWindowVisible(hStatusBar
)));
329 CheckMenuItem(menu
, IDM_FORMATICONBAR
, CHECKED_IF(IsWindowVisible(hwndTextEdit
)));
330 EnableMenuItem(menu
, IDM_FORMATICONBAR
, ENABLED_IF(activeTool
== TOOL_TEXT
));
332 CheckMenuItem(menu
, IDM_VIEWSHOWGRID
, CHECKED_IF(showGrid
));
333 CheckMenuItem(menu
, IDM_VIEWSHOWMINIATURE
, CHECKED_IF(showMiniature
));
335 case 3: /* Image menu */
336 EnableMenuItem(menu
, IDM_IMAGECROP
, ENABLED_IF(IsWindowVisible(hSelection
)));
337 CheckMenuItem(menu
, IDM_IMAGEDRAWOPAQUE
, CHECKED_IF(transpBg
== 0));
341 CheckMenuItem(menu
, IDM_VIEWZOOM125
, CHECKED_IF(zoom
== 125));
342 CheckMenuItem(menu
, IDM_VIEWZOOM25
, CHECKED_IF(zoom
== 250));
343 CheckMenuItem(menu
, IDM_VIEWZOOM50
, CHECKED_IF(zoom
== 500));
344 CheckMenuItem(menu
, IDM_VIEWZOOM100
, CHECKED_IF(zoom
== 1000));
345 CheckMenuItem(menu
, IDM_VIEWZOOM200
, CHECKED_IF(zoom
== 2000));
346 CheckMenuItem(menu
, IDM_VIEWZOOM400
, CHECKED_IF(zoom
== 4000));
347 CheckMenuItem(menu
, IDM_VIEWZOOM800
, CHECKED_IF(zoom
== 8000));
349 CheckMenuItem(menu
, IDM_COLORSMODERNPALETTE
, CHECKED_IF(selectedPalette
== 1));
350 CheckMenuItem(menu
, IDM_COLORSOLDPALETTE
, CHECKED_IF(selectedPalette
== 2));
355 if (hwnd
== hMainWnd
)
357 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
358 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
359 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (LPARAM
)&test
);
360 alignChildrenToMainWindow();
361 InvalidateRect(hwnd
, NULL
, TRUE
);
363 if (hwnd
== hImageArea
)
365 MoveWindow(hSizeboxLeftTop
,
368 MoveWindow(hSizeboxCenterTop
,
369 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
371 MoveWindow(hSizeboxRightTop
,
372 imgXRes
* zoom
/ 1000 + 3,
374 MoveWindow(hSizeboxLeftCenter
,
376 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
377 MoveWindow(hSizeboxRightCenter
,
378 imgXRes
* zoom
/ 1000 + 3,
379 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
380 MoveWindow(hSizeboxLeftBottom
,
382 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
383 MoveWindow(hSizeboxCenterBottom
,
384 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
385 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
386 MoveWindow(hSizeboxRightBottom
,
387 imgXRes
* zoom
/ 1000 + 3,
388 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
390 if (hwnd
== hImageArea
)
396 case WM_GETMINMAXINFO
:
397 if (hwnd
== hMainWnd
)
399 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
400 mm
->ptMinTrackSize
.x
= 330;
401 mm
->ptMinTrackSize
.y
= 430;
406 DefWindowProc(hwnd
, message
, wParam
, lParam
);
407 if (hwnd
== hImageArea
)
409 HDC hdc
= GetDC(hImageArea
);
410 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
412 if (showGrid
&& (zoom
>= 4000))
414 HPEN oldPen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
416 for(counter
= 0; counter
<= imgYRes
; counter
++)
418 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
419 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
421 for(counter
= 0; counter
<= imgXRes
; counter
++)
423 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
424 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
426 DeleteObject(SelectObject(hdc
, oldPen
));
428 ReleaseDC(hImageArea
, hdc
);
429 InvalidateRect(hSelection
, NULL
, FALSE
);
430 InvalidateRect(hwndMiniature
, NULL
, FALSE
);
432 else if (hwnd
== hwndMiniature
)
436 GetClientRect(hwndMiniature
, &mclient
);
437 hdc
= GetDC(hwndMiniature
);
438 StretchBlt(hdc
, 0, 0, mclient
.right
, mclient
.bottom
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
439 ReleaseDC(hwndMiniature
, hdc
);
443 // mouse events used for drawing
446 if (hwnd
== hImageArea
)
454 SetCursor(hCurColor
);
463 SetCursor(hCurAirbrush
);
466 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
470 DefWindowProc(hwnd
, message
, wParam
, lParam
);
474 if (hwnd
== hImageArea
)
476 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
478 SetCapture(hImageArea
);
480 startPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
485 SendMessage(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
488 InvalidateRect(hImageArea
, NULL
, FALSE
);
489 if ((activeTool
== TOOL_ZOOM
) && (zoom
< 8000))
490 zoomTo(zoom
* 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
495 if (hwnd
== hImageArea
)
497 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
499 SetCapture(hImageArea
);
501 startPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
506 SendMessage(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
509 InvalidateRect(hImageArea
, NULL
, FALSE
);
510 if ((activeTool
== TOOL_ZOOM
) && (zoom
> 125))
511 zoomTo(zoom
/ 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
516 if ((hwnd
== hImageArea
) && drawing
)
520 endPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
522 InvalidateRect(hImageArea
, NULL
, FALSE
);
523 if (activeTool
== TOOL_COLOR
)
526 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
527 if (tempColor
!= CLR_INVALID
)
529 InvalidateRect(hPalWin
, NULL
, FALSE
);
531 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
536 if ((hwnd
== hImageArea
) && drawing
)
540 endPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
542 InvalidateRect(hImageArea
, NULL
, FALSE
);
543 if (activeTool
== TOOL_COLOR
)
546 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
547 if (tempColor
!= CLR_INVALID
)
549 InvalidateRect(hPalWin
, NULL
, FALSE
);
551 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
556 if (wParam
== VK_ESCAPE
)
561 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
563 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
564 whilePaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
565 endPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
566 ShowWindow(hSelection
, SW_HIDE
);
569 /* FIXME: also cancel current drawing underway */
574 if (hwnd
== hImageArea
)
576 LONG xNow
= GET_X_LPARAM(lParam
) * 1000 / zoom
;
577 LONG yNow
= GET_Y_LPARAM(lParam
) * 1000 / zoom
;
578 if ((!drawing
) || (activeTool
<= TOOL_AIRBRUSH
))
582 if (activeTool
== TOOL_ZOOM
)
584 InvalidateRect(hImageArea
, NULL
, FALSE
);
585 UpdateWindow(hImageArea
);
586 drawZoomFrame(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
589 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
590 tme
.dwFlags
= TME_LEAVE
;
591 tme
.hwndTrack
= hImageArea
;
593 TrackMouseEvent(&tme
);
598 _stprintf(coordStr
, _T("%ld, %ld"), xNow
, yNow
);
599 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
604 /* values displayed in statusbar */
605 LONG xRel
= xNow
- start
.x
;
606 LONG yRel
= yNow
- start
.y
;
607 /* freesel, rectsel and text tools always show numbers limited to fit into image area */
608 if ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_TEXT
))
611 xRel
= (xNow
< 0) ? -start
.x
: xRel
;
612 else if (xNow
> imgXRes
)
613 xRel
= imgXRes
-start
.x
;
615 yRel
= (yNow
< 0) ? -start
.y
: yRel
;
616 else if (yNow
> imgYRes
)
617 yRel
= imgYRes
-start
.y
;
619 /* rectsel and shape tools always show non-negative numbers when drawing */
620 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_SHAPE
))
627 /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
637 _stprintf(coordStr
, _T("%ld, %ld"), xNow
, yNow
);
638 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
642 if ((wParam
& MK_LBUTTON
) != 0)
644 whilePaintingL(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
645 InvalidateRect(hImageArea
, NULL
, FALSE
);
646 if ((activeTool
>= TOOL_TEXT
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
649 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
651 _stprintf(sizeStr
, _T("%ld x %ld"), xRel
, yRel
);
652 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
655 if ((wParam
& MK_RBUTTON
) != 0)
657 whilePaintingR(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
658 InvalidateRect(hImageArea
, NULL
, FALSE
);
659 if (activeTool
>= TOOL_TEXT
)
662 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
664 _stprintf(sizeStr
, _T("%ld x %ld"), xRel
, yRel
);
665 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
673 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
674 if (activeTool
== TOOL_ZOOM
)
675 InvalidateRect(hImageArea
, NULL
, FALSE
);
678 // menu and button events
680 case WM_SYSCOLORCHANGE
:
682 /* Redirect message to common controls */
683 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
684 SendMessage(hToolbar
, WM_SYSCOLORCHANGE
, 0, 0);
689 switch (LOWORD(wParam
))
693 HICON paintIcon
= LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
));
694 TCHAR infotitle
[100];
696 LoadString(hProgInstance
, IDS_INFOTITLE
, infotitle
, SIZEOF(infotitle
));
697 LoadString(hProgInstance
, IDS_INFOTEXT
, infotext
, SIZEOF(infotext
));
698 ShellAbout(hMainWnd
, infotitle
, infotext
, paintIcon
);
699 DeleteObject(paintIcon
);
702 case IDM_HELPHELPTOPICS
:
703 //HtmlHelp(hMainWnd, "help\\Paint.chm", 0, 0);
706 SendMessage(hwnd
, WM_CLOSE
, wParam
, lParam
);
713 TCHAR programname
[20];
714 TCHAR saveprompttext
[100];
716 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
717 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
718 _stprintf(temptext
, saveprompttext
, filename
);
719 switch (MessageBox(hwnd
, temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
732 if (reset
&& imageSaved
)
734 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
735 InvalidateRect(hImageArea
, NULL
, FALSE
);
736 updateCanvasAndScrollbars();
742 if (GetOpenFileName(&ofn
) != 0)
744 HBITMAP bmNew
= NULL
;
745 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
748 UpdateApplicationProperties(bmNew
, ofn
.lpstrFileTitle
, ofn
.lpstrFileTitle
);
758 case IDM_FILEASWALLPAPERPLANE
:
759 SetWallpaper(filepathname
, 1, 1);
761 case IDM_FILEASWALLPAPERCENTERED
:
762 SetWallpaper(filepathname
, 1, 0);
764 case IDM_FILEASWALLPAPERSTRETCHED
:
765 SetWallpaper(filepathname
, 2, 0);
769 InvalidateRect(hImageArea
, NULL
, FALSE
);
773 InvalidateRect(hImageArea
, NULL
, FALSE
);
776 OpenClipboard(hMainWnd
);
778 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
783 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITCOPY
, 0);
784 /* Delete selection */
785 SendMessage(hwnd
, WM_COMMAND
, IDM_EDITDELETESELECTION
, 0);
788 OpenClipboard(hMainWnd
);
789 if (GetClipboardData(CF_BITMAP
) != NULL
)
791 InsertSelectionFromHBITMAP(GetClipboardData(CF_BITMAP
), hwnd
);
795 case IDM_EDITDELETESELECTION
:
797 /* remove selection window and already painted content using undo(),
798 paint Rect for rectangular selections and Poly for freeform selections */
800 if (activeTool
== TOOL_RECTSEL
)
803 Rect(hDrawingDC
, rectSel_dest
.left
, rectSel_dest
.top
, rectSel_dest
.right
,
804 rectSel_dest
.bottom
, bgColor
, bgColor
, 0, TRUE
);
806 if (activeTool
== TOOL_FREESEL
)
809 Poly(hDrawingDC
, ptStack
, ptSP
+ 1, 0, 0, 2, 0, FALSE
);
813 case IDM_EDITSELECTALL
:
815 HWND hToolbar
= FindWindowEx(hToolBoxContainer
, NULL
, TOOLBARCLASSNAME
, NULL
);
816 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
817 SendMessage(hwnd
, WM_COMMAND
, ID_RECTSEL
, 0);
818 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
819 whilePaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
820 endPaintingL(hDrawingDC
, imgXRes
, imgYRes
, fgColor
, bgColor
);
824 if (GetSaveFileName(&ofn
) != 0)
825 SaveDIBToFile(hSelBm
, ofn
.lpstrFile
, hDrawingDC
, NULL
, NULL
, fileHPPM
, fileVPPM
);
827 case IDM_EDITPASTEFROM
:
828 if (GetOpenFileName(&ofn
) != 0)
830 HBITMAP bmNew
= NULL
;
831 LoadDIBFromFile(&bmNew
, ofn
.lpstrFile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
834 InsertSelectionFromHBITMAP(bmNew
, hwnd
);
839 case IDM_COLORSEDITPALETTE
:
840 if (ChooseColor(&choosecolor
))
842 fgColor
= choosecolor
.rgbResult
;
843 InvalidateRect(hPalWin
, NULL
, FALSE
);
846 case IDM_COLORSMODERNPALETTE
:
848 CopyMemory(palColors
, modernPalColors
, sizeof(palColors
));
849 InvalidateRect(hPalWin
, NULL
, FALSE
);
851 case IDM_COLORSOLDPALETTE
:
853 CopyMemory(palColors
, oldPalColors
, sizeof(palColors
));
854 InvalidateRect(hPalWin
, NULL
, FALSE
);
856 case IDM_IMAGEINVERTCOLORS
:
860 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
861 InvertRect(hDrawingDC
, &tempRect
);
862 InvalidateRect(hImageArea
, NULL
, FALSE
);
865 case IDM_IMAGEDELETEIMAGE
:
867 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
868 InvalidateRect(hImageArea
, NULL
, FALSE
);
870 case IDM_IMAGEROTATEMIRROR
:
871 switch (mirrorRotateDlg())
873 case 1: /* flip horizontally */
874 if (IsWindowVisible(hSelection
))
876 SelectObject(hSelDC
, hSelMask
);
877 StretchBlt(hSelDC
, RECT_WIDTH(rectSel_dest
) - 1, 0, -RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), hSelDC
,
878 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), SRCCOPY
);
879 SelectObject(hSelDC
, hSelBm
);
880 StretchBlt(hSelDC
, RECT_WIDTH(rectSel_dest
) - 1, 0, -RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), hSelDC
,
881 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), SRCCOPY
);
882 ForceRefreshSelectionContents();
887 StretchBlt(hDrawingDC
, imgXRes
- 1, 0, -imgXRes
, imgYRes
, hDrawingDC
, 0, 0,
888 imgXRes
, imgYRes
, SRCCOPY
);
889 InvalidateRect(hImageArea
, NULL
, FALSE
);
892 case 2: /* flip vertically */
893 if (IsWindowVisible(hSelection
))
895 SelectObject(hSelDC
, hSelMask
);
896 StretchBlt(hSelDC
, 0, RECT_HEIGHT(rectSel_dest
) - 1, RECT_WIDTH(rectSel_dest
), -RECT_HEIGHT(rectSel_dest
), hSelDC
,
897 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), SRCCOPY
);
898 SelectObject(hSelDC
, hSelBm
);
899 StretchBlt(hSelDC
, 0, RECT_HEIGHT(rectSel_dest
) - 1, RECT_WIDTH(rectSel_dest
), -RECT_HEIGHT(rectSel_dest
), hSelDC
,
900 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), SRCCOPY
);
901 ForceRefreshSelectionContents();
906 StretchBlt(hDrawingDC
, 0, imgYRes
- 1, imgXRes
, -imgYRes
, hDrawingDC
, 0, 0,
907 imgXRes
, imgYRes
, SRCCOPY
);
908 InvalidateRect(hImageArea
, NULL
, FALSE
);
911 case 3: /* rotate 90 degrees */
913 case 4: /* rotate 180 degrees */
914 if (IsWindowVisible(hSelection
))
916 SelectObject(hSelDC
, hSelMask
);
917 StretchBlt(hSelDC
, RECT_WIDTH(rectSel_dest
) - 1, RECT_HEIGHT(rectSel_dest
) - 1, -RECT_WIDTH(rectSel_dest
), -RECT_HEIGHT(rectSel_dest
), hSelDC
,
918 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), SRCCOPY
);
919 SelectObject(hSelDC
, hSelBm
);
920 StretchBlt(hSelDC
, RECT_WIDTH(rectSel_dest
) - 1, RECT_HEIGHT(rectSel_dest
) - 1, -RECT_WIDTH(rectSel_dest
), -RECT_HEIGHT(rectSel_dest
), hSelDC
,
921 0, 0, RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), SRCCOPY
);
922 ForceRefreshSelectionContents();
927 StretchBlt(hDrawingDC
, imgXRes
- 1, imgYRes
- 1, -imgXRes
, -imgYRes
, hDrawingDC
,
928 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
929 InvalidateRect(hImageArea
, NULL
, FALSE
);
932 case 5: /* rotate 270 degrees */
936 case IDM_IMAGEATTRIBUTES
:
940 cropReversible(widthSetInDlg
, heightSetInDlg
, 0, 0);
941 updateCanvasAndScrollbars();
945 case IDM_IMAGESTRETCHSKEW
:
949 insertReversible(CopyImage(hBms
[currInd
], IMAGE_BITMAP
,
950 imgXRes
* stretchSkew
.percentage
.x
/ 100,
951 imgYRes
* stretchSkew
.percentage
.y
/ 100, 0));
952 updateCanvasAndScrollbars();
956 case IDM_IMAGEDRAWOPAQUE
:
957 transpBg
= 1 - transpBg
;
958 InvalidateRect(hToolSettings
, NULL
, TRUE
);
961 insertReversible(CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
962 updateCanvasAndScrollbars();
965 case IDM_VIEWTOOLBOX
:
966 ShowWindow(hToolBoxContainer
, IsWindowVisible(hToolBoxContainer
) ? SW_HIDE
: SW_SHOW
);
967 alignChildrenToMainWindow();
969 case IDM_VIEWCOLORPALETTE
:
970 ShowWindow(hPalWin
, IsWindowVisible(hPalWin
) ? SW_HIDE
: SW_SHOW
);
971 alignChildrenToMainWindow();
973 case IDM_VIEWSTATUSBAR
:
974 ShowWindow(hStatusBar
, IsWindowVisible(hStatusBar
) ? SW_HIDE
: SW_SHOW
);
975 alignChildrenToMainWindow();
977 case IDM_FORMATICONBAR
:
978 ShowWindow(hwndTextEdit
, IsWindowVisible(hwndTextEdit
) ? SW_HIDE
: SW_SHOW
);
980 case IDM_VIEWSHOWGRID
:
981 showGrid
= !showGrid
;
982 InvalidateRect(hImageArea
, NULL
, FALSE
);
984 case IDM_VIEWSHOWMINIATURE
:
985 showMiniature
= !showMiniature
;
986 ShowWindow(hwndMiniature
, showMiniature
? SW_SHOW
: SW_HIDE
);
989 case IDM_VIEWZOOM125
:
998 case IDM_VIEWZOOM100
:
1001 case IDM_VIEWZOOM200
:
1004 case IDM_VIEWZOOM400
:
1007 case IDM_VIEWZOOM800
:
1061 return DefWindowProc(hwnd
, message
, wParam
, lParam
);