2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint_new/winproc.cpp
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 selectionWindow
.ShowWindow(SW_HIDE
);
24 pointSP
= 0; // resets the point-buffer of the polygon and bezier functions
25 toolSettingsWindow
.Invalidate(TRUE
);
26 ShowWindow(hTrackbarZoom
, (tool
== TOOL_ZOOM
) ? SW_SHOW
: SW_HIDE
);
27 textEditWindow
.ShowWindow((tool
== TOOL_TEXT
) ? SW_SHOW
: SW_HIDE
);
31 updateCanvasAndScrollbars()
33 selectionWindow
.ShowWindow(SW_HIDE
);
34 imageArea
.MoveWindow(3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
35 scrollboxWindow
.Invalidate(TRUE
);
36 imageArea
.Invalidate(FALSE
);
38 scrollboxWindow
.SetScrollPos(SB_HORZ
, 0, TRUE
);
39 scrollboxWindow
.SetScrollPos(SB_VERT
, 0, TRUE
);
43 zoomTo(int newZoom
, int mouseX
, int mouseY
)
46 int tempZoom
= newZoom
;
48 RECT clientRectScrollbox
;
49 RECT clientRectImageArea
;
51 scrollboxWindow
.GetClientRect(&clientRectScrollbox
);
52 imageArea
.GetClientRect(&clientRectImageArea
);
53 w
= clientRectImageArea
.right
* clientRectScrollbox
.right
/ (clientRectImageArea
.right
* newZoom
/ zoom
);
54 h
= clientRectImageArea
.bottom
* clientRectScrollbox
.bottom
/ (clientRectImageArea
.bottom
* newZoom
/ zoom
);
55 x
= max(0, min(clientRectImageArea
.right
- w
, mouseX
- w
/ 2)) * newZoom
/ zoom
;
56 y
= max(0, min(clientRectImageArea
.bottom
- h
, mouseY
- h
/ 2)) * newZoom
/ zoom
;
60 selectionWindow
.ShowWindow(SW_HIDE
);
61 imageArea
.MoveWindow(3, 3, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, FALSE
);
62 scrollboxWindow
.Invalidate(TRUE
);
63 imageArea
.Invalidate(FALSE
);
65 scrollboxWindow
.SendMessage(WM_HSCROLL
, SB_THUMBPOSITION
| (x
<< 16), 0);
66 scrollboxWindow
.SendMessage(WM_VSCROLL
, SB_THUMBPOSITION
| (y
<< 16), 0);
68 while (tempZoom
> 125)
71 tempZoom
= tempZoom
>> 1;
73 SendMessage(hTrackbarZoom
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) tbPos
);
77 drawZoomFrame(int mouseX
, int mouseY
)
85 RECT clientRectScrollbox
;
86 RECT clientRectImageArea
;
88 scrollboxWindow
.GetClientRect(&clientRectScrollbox
);
89 imageArea
.GetClientRect(&clientRectImageArea
);
90 w
= clientRectImageArea
.right
* clientRectScrollbox
.right
/ (clientRectImageArea
.right
* 2);
91 h
= clientRectImageArea
.bottom
* clientRectScrollbox
.bottom
/ (clientRectImageArea
.bottom
* 2);
92 x
= max(0, min(clientRectImageArea
.right
- w
, mouseX
- w
/ 2));
93 y
= max(0, min(clientRectImageArea
.bottom
- h
, mouseY
- h
/ 2));
95 hdc
= imageArea
.GetDC();
96 oldPen
= (HPEN
) SelectObject(hdc
, CreatePen(PS_SOLID
, 0, 0));
97 logbrush
.lbStyle
= BS_HOLLOW
;
98 oldBrush
= (HBRUSH
) SelectObject(hdc
, CreateBrushIndirect(&logbrush
));
99 rop
= SetROP2(hdc
, R2_NOT
);
100 Rectangle(hdc
, x
, y
, x
+ w
, y
+ h
);
102 DeleteObject(SelectObject(hdc
, oldBrush
));
103 DeleteObject(SelectObject(hdc
, oldPen
));
104 imageArea
.ReleaseDC(hdc
);
108 alignChildrenToMainWindow()
112 mainWindow
.GetClientRect(&clientRect
);
114 if (toolBoxContainer
.IsWindowVisible())
117 w
= clientRect
.right
- 56;
122 w
= clientRect
.right
;
124 if (paletteWindow
.IsWindowVisible())
127 h
= clientRect
.bottom
- 49;
132 h
= clientRect
.bottom
- 3;
135 scrollboxWindow
.MoveWindow(x
, y
, w
, IsWindowVisible(hStatusBar
) ? h
- 23 : h
, TRUE
);
136 paletteWindow
.MoveWindow(x
, 9, 255, 32, TRUE
);
140 saveImage(BOOL overwrite
)
142 if (isAFile
&& overwrite
)
144 SaveDIBToFile(hBms
[currInd
], filepathname
, hDrawingDC
, &fileTime
, &fileSize
, fileHPPM
,
148 else if (GetSaveFileName(&sfn
) != 0)
152 SaveDIBToFile(hBms
[currInd
], sfn
.lpstrFile
, hDrawingDC
, &fileTime
, &fileSize
,
154 CopyMemory(filename
, sfn
.lpstrFileTitle
, sizeof(filename
));
155 CopyMemory(filepathname
, sfn
.lpstrFile
, sizeof(filepathname
));
156 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
157 _stprintf(tempstr
, resstr
, filename
);
158 mainWindow
.SetWindowText(tempstr
);
165 UpdateApplicationProperties(HBITMAP bitmap
, LPTSTR newfilename
, LPTSTR newfilepathname
)
169 insertReversible(bitmap
);
170 updateCanvasAndScrollbars();
171 CopyMemory(filename
, newfilename
, sizeof(filename
));
172 CopyMemory(filepathname
, newfilepathname
, sizeof(filepathname
));
173 LoadString(hProgInstance
, IDS_WINDOWTITLE
, resstr
, SIZEOF(resstr
));
174 _stprintf(tempstr
, resstr
, filename
);
175 mainWindow
.SetWindowText(tempstr
);
181 InsertSelectionFromHBITMAP(HBITMAP bitmap
, HWND window
)
186 HWND hToolbar
= FindWindowEx(toolBoxContainer
.m_hWnd
, NULL
, TOOLBARCLASSNAME
, NULL
);
187 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
188 SendMessage(window
, WM_COMMAND
, ID_RECTSEL
, 0);
190 DeleteObject(SelectObject(hSelDC
, hSelBm
= (HBITMAP
) CopyImage(bitmap
,
194 SetRectEmpty(&rectSel_src
);
195 rectSel_dest
.left
= rectSel_dest
.top
= 0;
196 rectSel_dest
.right
= rectSel_dest
.left
+ GetDIBWidth(hSelBm
);
197 rectSel_dest
.bottom
= rectSel_dest
.top
+ GetDIBHeight(hSelBm
);
199 hTempDC
= CreateCompatibleDC(hSelDC
);
200 hTempMask
= CreateBitmap(RECT_WIDTH(rectSel_dest
), RECT_HEIGHT(rectSel_dest
), 1, 1, NULL
);
201 SelectObject(hTempDC
, hTempMask
);
202 Rect(hTempDC
, rectSel_dest
.left
, rectSel_dest
.top
, rectSel_dest
.right
, rectSel_dest
.bottom
, 0x00ffffff, 0x00ffffff, 1, 1);
203 DeleteObject(hSelMask
);
204 hSelMask
= hTempMask
;
208 selectionWindow
.ShowWindow(SW_SHOW
);
209 ForceRefreshSelectionContents();
214 LRESULT
CMainWindow::OnDropFiles(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
217 TCHAR droppedfile
[MAX_PATH
];
218 HBITMAP bmNew
= NULL
;
219 drophandle
= (HDROP
)wParam
;
220 DragQueryFile(drophandle
, 0, droppedfile
, SIZEOF(droppedfile
));
221 DragFinish(drophandle
);
222 LoadDIBFromFile(&bmNew
, droppedfile
, &fileTime
, &fileSize
, &fileHPPM
, &fileVPPM
);
226 pathend
= _tcsrchr(droppedfile
, '\\');
228 UpdateApplicationProperties(bmNew
, pathend
, pathend
);
233 LRESULT
CMainWindow::OnCreate(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
235 SendMessage(WM_SETICON
, ICON_BIG
, (LPARAM
) LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
)));
236 SendMessage(WM_SETICON
, ICON_SMALL
, (LPARAM
) LoadIcon(hProgInstance
, MAKEINTRESOURCE(IDI_APPICON
)));
242 LRESULT
CMainWindow::OnDestroy(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
244 PostQuitMessage(0); /* send a WM_QUIT to the message queue */
248 LRESULT
CMainWindow::OnClose(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
250 if (m_hWnd
== miniature
.m_hWnd
)
252 miniature
.ShowWindow(SW_HIDE
);
253 showMiniature
= FALSE
;
258 TCHAR programname
[20];
259 TCHAR saveprompttext
[100];
261 LoadString(hProgInstance
, IDS_PROGRAMNAME
, programname
, SIZEOF(programname
));
262 LoadString(hProgInstance
, IDS_SAVEPROMPTTEXT
, saveprompttext
, SIZEOF(saveprompttext
));
263 _stprintf(temptext
, saveprompttext
, filename
);
264 switch (MessageBox(temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
283 LRESULT
CMainWindow::OnInitMenuPopup(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
285 HMENU menu
= GetMenu();
286 BOOL trueSelection
= (selectionWindow
.IsWindowVisible() && ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
)));
289 case 0: /* File menu */
290 EnableMenuItem(menu
, IDM_FILEASWALLPAPERPLANE
, ENABLED_IF(isAFile
));
291 EnableMenuItem(menu
, IDM_FILEASWALLPAPERCENTERED
, ENABLED_IF(isAFile
));
292 EnableMenuItem(menu
, IDM_FILEASWALLPAPERSTRETCHED
, ENABLED_IF(isAFile
));
294 case 1: /* Edit menu */
295 EnableMenuItem(menu
, IDM_EDITUNDO
, ENABLED_IF(undoSteps
> 0));
296 EnableMenuItem(menu
, IDM_EDITREDO
, ENABLED_IF(redoSteps
> 0));
297 EnableMenuItem(menu
, IDM_EDITCUT
, ENABLED_IF(trueSelection
));
298 EnableMenuItem(menu
, IDM_EDITCOPY
, ENABLED_IF(trueSelection
));
299 EnableMenuItem(menu
, IDM_EDITDELETESELECTION
, ENABLED_IF(trueSelection
));
300 EnableMenuItem(menu
, IDM_EDITINVERTSELECTION
, ENABLED_IF(trueSelection
));
301 EnableMenuItem(menu
, IDM_EDITCOPYTO
, ENABLED_IF(trueSelection
));
303 EnableMenuItem(menu
, IDM_EDITPASTE
, ENABLED_IF(GetClipboardData(CF_BITMAP
) != NULL
));
306 case 2: /* View menu */
307 CheckMenuItem(menu
, IDM_VIEWTOOLBOX
, CHECKED_IF(toolBoxContainer
.IsWindowVisible()));
308 CheckMenuItem(menu
, IDM_VIEWCOLORPALETTE
, CHECKED_IF(paletteWindow
.IsWindowVisible()));
309 CheckMenuItem(menu
, IDM_VIEWSTATUSBAR
, CHECKED_IF(::IsWindowVisible(hStatusBar
)));
310 CheckMenuItem(menu
, IDM_FORMATICONBAR
, CHECKED_IF(textEditWindow
.IsWindowVisible()));
311 EnableMenuItem(menu
, IDM_FORMATICONBAR
, ENABLED_IF(activeTool
== TOOL_TEXT
));
313 CheckMenuItem(menu
, IDM_VIEWSHOWGRID
, CHECKED_IF(showGrid
));
314 CheckMenuItem(menu
, IDM_VIEWSHOWMINIATURE
, CHECKED_IF(showMiniature
));
316 case 3: /* Image menu */
317 EnableMenuItem(menu
, IDM_IMAGECROP
, ENABLED_IF(selectionWindow
.IsWindowVisible()));
318 CheckMenuItem(menu
, IDM_IMAGEDRAWOPAQUE
, CHECKED_IF(transpBg
== 0));
322 CheckMenuItem(menu
, IDM_VIEWZOOM125
, CHECKED_IF(zoom
== 125));
323 CheckMenuItem(menu
, IDM_VIEWZOOM25
, CHECKED_IF(zoom
== 250));
324 CheckMenuItem(menu
, IDM_VIEWZOOM50
, CHECKED_IF(zoom
== 500));
325 CheckMenuItem(menu
, IDM_VIEWZOOM100
, CHECKED_IF(zoom
== 1000));
326 CheckMenuItem(menu
, IDM_VIEWZOOM200
, CHECKED_IF(zoom
== 2000));
327 CheckMenuItem(menu
, IDM_VIEWZOOM400
, CHECKED_IF(zoom
== 4000));
328 CheckMenuItem(menu
, IDM_VIEWZOOM800
, CHECKED_IF(zoom
== 8000));
330 CheckMenuItem(menu
, IDM_COLORSMODERNPALETTE
, CHECKED_IF(selectedPalette
== 1));
331 CheckMenuItem(menu
, IDM_COLORSOLDPALETTE
, CHECKED_IF(selectedPalette
== 2));
335 LRESULT
CMainWindow::OnSize(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
337 if (m_hWnd
== mainWindow
.m_hWnd
)
339 int test
[] = { LOWORD(lParam
) - 260, LOWORD(lParam
) - 140, LOWORD(lParam
) - 20 };
340 SendMessage(hStatusBar
, WM_SIZE
, wParam
, lParam
);
341 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (LPARAM
)&test
);
342 alignChildrenToMainWindow();
345 if (m_hWnd
== imageArea
.m_hWnd
)
347 sizeboxLeftTop
.MoveWindow(
350 sizeboxCenterTop
.MoveWindow(
351 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
353 sizeboxRightTop
.MoveWindow(
354 imgXRes
* zoom
/ 1000 + 3,
356 sizeboxLeftCenter
.MoveWindow(
358 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
359 sizeboxRightCenter
.MoveWindow(
360 imgXRes
* zoom
/ 1000 + 3,
361 imgYRes
* zoom
/ 2000 + 3 * 3 / 4, 3, 3, TRUE
);
362 sizeboxLeftBottom
.MoveWindow(
364 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
365 sizeboxCenterBottom
.MoveWindow(
366 imgXRes
* zoom
/ 2000 + 3 * 3 / 4,
367 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
368 sizeboxRightBottom
.MoveWindow(
369 imgXRes
* zoom
/ 1000 + 3,
370 imgYRes
* zoom
/ 1000 + 3, 3, 3, TRUE
);
372 if (m_hWnd
== imageArea
.m_hWnd
)
379 LRESULT
CMainWindow::OnGetMinMaxInfo(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
381 if (m_hWnd
== mainWindow
.m_hWnd
)
383 MINMAXINFO
*mm
= (LPMINMAXINFO
) lParam
;
384 mm
->ptMinTrackSize
.x
= 330;
385 mm
->ptMinTrackSize
.y
= 430;
390 LRESULT
CMainWindow::OnPaint(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
392 DefWindowProc(WM_PAINT
, wParam
, lParam
);
393 if (m_hWnd
== imageArea
.m_hWnd
)
395 HDC hdc
= imageArea
.GetDC();
396 StretchBlt(hdc
, 0, 0, imgXRes
* zoom
/ 1000, imgYRes
* zoom
/ 1000, hDrawingDC
, 0, 0, imgXRes
,
398 if (showGrid
&& (zoom
>= 4000))
400 HPEN oldPen
= (HPEN
) SelectObject(hdc
, CreatePen(PS_SOLID
, 1, 0x00a0a0a0));
402 for(counter
= 0; counter
<= imgYRes
; counter
++)
404 MoveToEx(hdc
, 0, counter
* zoom
/ 1000, NULL
);
405 LineTo(hdc
, imgXRes
* zoom
/ 1000, counter
* zoom
/ 1000);
407 for(counter
= 0; counter
<= imgXRes
; counter
++)
409 MoveToEx(hdc
, counter
* zoom
/ 1000, 0, NULL
);
410 LineTo(hdc
, counter
* zoom
/ 1000, imgYRes
* zoom
/ 1000);
412 DeleteObject(SelectObject(hdc
, oldPen
));
414 imageArea
.ReleaseDC(hdc
);
415 selectionWindow
.Invalidate(FALSE
);
416 miniature
.Invalidate(FALSE
);
418 else if (m_hWnd
== miniature
.m_hWnd
)
422 miniature
.GetClientRect(&mclient
);
423 hdc
= miniature
.GetDC();
424 StretchBlt(hdc
, 0, 0, mclient
.right
, mclient
.bottom
, hDrawingDC
, 0, 0, imgXRes
, imgYRes
, SRCCOPY
);
425 miniature
.ReleaseDC(hdc
);
430 LRESULT
CMainWindow::OnSetCursor(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
432 if (m_hWnd
== imageArea
.m_hWnd
)
440 SetCursor(hCurColor
);
449 SetCursor(hCurAirbrush
);
452 SetCursor(LoadCursor(NULL
, IDC_CROSS
));
456 SetCursor(LoadCursor(NULL
, IDC_ARROW
));
460 LRESULT
CMainWindow::OnLButtonDown(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
462 if (m_hWnd
== imageArea
.m_hWnd
)
464 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
468 startPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
473 SendMessage(WM_LBUTTONUP
, wParam
, lParam
);
477 if ((activeTool
== TOOL_ZOOM
) && (zoom
< 8000))
478 zoomTo(zoom
* 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
483 LRESULT
CMainWindow::OnRButtonDown(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
485 if (m_hWnd
== imageArea
.m_hWnd
)
487 if ((!drawing
) || (activeTool
== TOOL_COLOR
))
491 startPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
,
496 SendMessage(WM_RBUTTONUP
, wParam
, lParam
);
500 if ((activeTool
== TOOL_ZOOM
) && (zoom
> 125))
501 zoomTo(zoom
/ 2, GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
506 LRESULT
CMainWindow::OnLButtonUp(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
508 if ((m_hWnd
== imageArea
.m_hWnd
) && drawing
)
512 endPaintingL(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
515 if (activeTool
== TOOL_COLOR
)
518 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
519 if (tempColor
!= CLR_INVALID
)
521 paletteWindow
.Invalidate(FALSE
);
523 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
528 LRESULT
CMainWindow::OnRButtonUp(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
530 if ((m_hWnd
== imageArea
.m_hWnd
) && drawing
)
534 endPaintingR(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
, fgColor
,
537 if (activeTool
== TOOL_COLOR
)
540 GetPixel(hDrawingDC
, GET_X_LPARAM(lParam
) * 1000 / zoom
, GET_Y_LPARAM(lParam
) * 1000 / zoom
);
541 if (tempColor
!= CLR_INVALID
)
543 paletteWindow
.Invalidate(FALSE
);
545 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) "");
550 LRESULT
CMainWindow::OnKeyDown(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
552 if (wParam
== VK_ESCAPE
)
557 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
559 startPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
560 whilePaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
561 endPaintingL(hDrawingDC
, 0, 0, fgColor
, bgColor
);
562 selectionWindow
.ShowWindow(SW_HIDE
);
565 /* FIXME: also cancel current drawing underway */
570 LRESULT
CMainWindow::OnMouseMove(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
572 if (m_hWnd
== imageArea
.m_hWnd
)
574 LONG xNow
= GET_X_LPARAM(lParam
) * 1000 / zoom
;
575 LONG yNow
= GET_Y_LPARAM(lParam
) * 1000 / zoom
;
576 if ((!drawing
) || (activeTool
<= TOOL_AIRBRUSH
))
580 if (activeTool
== TOOL_ZOOM
)
584 drawZoomFrame(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
587 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
588 tme
.dwFlags
= TME_LEAVE
;
589 tme
.hwndTrack
= imageArea
.m_hWnd
;
591 TrackMouseEvent(&tme
);
596 _stprintf(coordStr
, _T("%ld, %ld"), xNow
, yNow
);
597 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
602 /* values displayed in statusbar */
603 LONG xRel
= xNow
- start
.x
;
604 LONG yRel
= yNow
- start
.y
;
605 /* freesel, rectsel and text tools always show numbers limited to fit into image area */
606 if ((activeTool
== TOOL_FREESEL
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_TEXT
))
609 xRel
= (xNow
< 0) ? -start
.x
: xRel
;
610 else if (xNow
> imgXRes
)
611 xRel
= imgXRes
-start
.x
;
613 yRel
= (yNow
< 0) ? -start
.y
: yRel
;
614 else if (yNow
> imgYRes
)
615 yRel
= imgYRes
-start
.y
;
617 /* rectsel and shape tools always show non-negative numbers when drawing */
618 if ((activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_SHAPE
))
625 /* while drawing, update cursor coordinates only for tools 3, 7, 8, 9, 14 */
635 _stprintf(coordStr
, _T("%ld, %ld"), xNow
, yNow
);
636 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) coordStr
);
640 if ((wParam
& MK_LBUTTON
) != 0)
642 whilePaintingL(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
644 if ((activeTool
>= TOOL_TEXT
) || (activeTool
== TOOL_RECTSEL
) || (activeTool
== TOOL_FREESEL
))
647 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
649 _stprintf(sizeStr
, _T("%ld x %ld"), xRel
, yRel
);
650 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
653 if ((wParam
& MK_RBUTTON
) != 0)
655 whilePaintingR(hDrawingDC
, xNow
, yNow
, fgColor
, bgColor
);
657 if (activeTool
>= TOOL_TEXT
)
660 if ((activeTool
>= TOOL_LINE
) && (GetAsyncKeyState(VK_SHIFT
) < 0))
662 _stprintf(sizeStr
, _T("%ld x %ld"), xRel
, yRel
);
663 SendMessage(hStatusBar
, SB_SETTEXT
, 2, (LPARAM
) sizeStr
);
671 LRESULT
CMainWindow::OnMouseLeave(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
673 SendMessage(hStatusBar
, SB_SETTEXT
, 1, (LPARAM
) _T(""));
674 if (activeTool
== TOOL_ZOOM
)
675 imageArea
.Invalidate(FALSE
);
679 LRESULT
CMainWindow::OnSysColorChange(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
681 /* Redirect message to common controls */
682 HWND hToolbar
= FindWindowEx(toolBoxContainer
.m_hWnd
, NULL
, TOOLBARCLASSNAME
, NULL
);
683 SendMessage(hToolbar
, WM_SYSCOLORCHANGE
, 0, 0);
687 LRESULT
CMainWindow::OnCommand(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
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(mainWindow
.m_hWnd
, infotitle
, infotext
, paintIcon
);
699 DeleteObject(paintIcon
);
702 case IDM_HELPHELPTOPICS
:
703 HtmlHelp(mainWindow
.m_hWnd
, _T("help\\Paint.chm"), 0, 0);
706 SendMessage(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(temptext
, programname
, MB_YESNOCANCEL
| MB_ICONQUESTION
))
732 if (reset
&& imageSaved
)
734 Rectangle(hDrawingDC
, 0 - 1, 0 - 1, imgXRes
+ 1, imgYRes
+ 1);
735 imageArea
.Invalidate(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 imageArea
.Invalidate(FALSE
);
773 imageArea
.Invalidate(FALSE
);
778 SetClipboardData(CF_BITMAP
, CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
783 SendMessage(WM_COMMAND
, IDM_EDITCOPY
, 0);
784 /* Delete selection */
785 SendMessage(WM_COMMAND
, IDM_EDITDELETESELECTION
, 0);
789 if (GetClipboardData(CF_BITMAP
) != NULL
)
791 InsertSelectionFromHBITMAP((HBITMAP
) GetClipboardData(CF_BITMAP
), m_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
, TRUE
);
813 case IDM_EDITSELECTALL
:
815 HWND hToolbar
= FindWindowEx(toolBoxContainer
.m_hWnd
, NULL
, TOOLBARCLASSNAME
, NULL
);
816 SendMessage(hToolbar
, TB_CHECKBUTTON
, ID_RECTSEL
, MAKELONG(TRUE
, 0));
817 SendMessage(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
, m_hWnd
);
839 case IDM_COLORSEDITPALETTE
:
840 if (ChooseColor(&choosecolor
))
842 fgColor
= choosecolor
.rgbResult
;
843 paletteWindow
.Invalidate(FALSE
);
846 case IDM_COLORSMODERNPALETTE
:
848 CopyMemory(palColors
, modernPalColors
, sizeof(palColors
));
849 paletteWindow
.Invalidate(FALSE
);
851 case IDM_COLORSOLDPALETTE
:
853 CopyMemory(palColors
, oldPalColors
, sizeof(palColors
));
854 paletteWindow
.Invalidate(FALSE
);
856 case IDM_IMAGEINVERTCOLORS
:
860 SetRect(&tempRect
, 0, 0, imgXRes
, imgYRes
);
861 InvertRect(hDrawingDC
, &tempRect
);
862 imageArea
.Invalidate(FALSE
);
865 case IDM_IMAGEDELETEIMAGE
:
867 Rect(hDrawingDC
, 0, 0, imgXRes
, imgYRes
, bgColor
, bgColor
, 0, TRUE
);
868 imageArea
.Invalidate(FALSE
);
870 case IDM_IMAGEROTATEMIRROR
:
871 switch (mirrorRotateDlg())
873 case 1: /* flip horizontally */
874 if (selectionWindow
.IsWindowVisible())
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 imageArea
.Invalidate(FALSE
);
892 case 2: /* flip vertically */
893 if (selectionWindow
.IsWindowVisible())
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 imageArea
.Invalidate(FALSE
);
911 case 3: /* rotate 90 degrees */
913 case 4: /* rotate 180 degrees */
914 if (selectionWindow
.IsWindowVisible())
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 imageArea
.Invalidate(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((HBITMAP
) 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 toolSettingsWindow
.Invalidate(TRUE
);
961 insertReversible((HBITMAP
) CopyImage(hSelBm
, IMAGE_BITMAP
, 0, 0, LR_COPYRETURNORG
));
962 updateCanvasAndScrollbars();
965 case IDM_VIEWTOOLBOX
:
966 toolBoxContainer
.ShowWindow(toolBoxContainer
.IsWindowVisible() ? SW_HIDE
: SW_SHOW
);
967 alignChildrenToMainWindow();
969 case IDM_VIEWCOLORPALETTE
:
970 paletteWindow
.ShowWindow(paletteWindow
.IsWindowVisible() ? 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 textEditWindow
.ShowWindow(textEditWindow
.IsWindowVisible() ? SW_HIDE
: SW_SHOW
);
980 case IDM_VIEWSHOWGRID
:
981 showGrid
= !showGrid
;
982 imageArea
.Invalidate(FALSE
);
984 case IDM_VIEWSHOWMINIATURE
:
985 showMiniature
= !showMiniature
;
986 miniature
.ShowWindow(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
: