1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:    PAINT for ReactOS
38f1f1c7aSStanislav Motylkov  * LICENSE:    LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4c2c66affSColin Finck  * PURPOSE:    Window procedure of the main window and all children apart from
5c2c66affSColin Finck  *             hPalWin, hToolSettings and hSelection
6f5200e6cSStanislav Motylkov  * COPYRIGHT:  Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
78f1f1c7aSStanislav Motylkov  *             Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
8c2c66affSColin Finck  */
9c2c66affSColin Finck 
10c2c66affSColin Finck #include "precomp.h"
11c2c66affSColin Finck 
1229e147beSKatayama Hirofumi MZ CMiniatureWindow miniature;
1329e147beSKatayama Hirofumi MZ 
14c2c66affSColin Finck /* FUNCTIONS ********************************************************/
15c2c66affSColin Finck 
CMiniatureWindow()162f856f6fSKatayama Hirofumi MZ CMiniatureWindow::CMiniatureWindow()
172f856f6fSKatayama Hirofumi MZ     : m_hbmCached(NULL)
182f856f6fSKatayama Hirofumi MZ {
192f856f6fSKatayama Hirofumi MZ }
202f856f6fSKatayama Hirofumi MZ 
~CMiniatureWindow()212f856f6fSKatayama Hirofumi MZ CMiniatureWindow::~CMiniatureWindow()
222f856f6fSKatayama Hirofumi MZ {
232f856f6fSKatayama Hirofumi MZ     if (m_hbmCached)
242f856f6fSKatayama Hirofumi MZ         ::DeleteObject(m_hbmCached);
252f856f6fSKatayama Hirofumi MZ }
262f856f6fSKatayama Hirofumi MZ 
DoCreate(HWND hwndParent)2729e147beSKatayama Hirofumi MZ HWND CMiniatureWindow::DoCreate(HWND hwndParent)
2829e147beSKatayama Hirofumi MZ {
2929e147beSKatayama Hirofumi MZ     if (m_hWnd)
3029e147beSKatayama Hirofumi MZ         return m_hWnd;
3129e147beSKatayama Hirofumi MZ 
3229e147beSKatayama Hirofumi MZ     RECT rc =
3329e147beSKatayama Hirofumi MZ     {
3429e147beSKatayama Hirofumi MZ         (LONG)registrySettings.ThumbXPos, (LONG)registrySettings.ThumbYPos,
3529e147beSKatayama Hirofumi MZ         (LONG)(registrySettings.ThumbXPos + registrySettings.ThumbWidth),
3629e147beSKatayama Hirofumi MZ         (LONG)(registrySettings.ThumbYPos + registrySettings.ThumbHeight)
3729e147beSKatayama Hirofumi MZ     };
3829e147beSKatayama Hirofumi MZ 
39640d67d1SKatayama Hirofumi MZ     WCHAR strTitle[100];
40640d67d1SKatayama Hirofumi MZ     ::LoadStringW(g_hinstExe, IDS_MINIATURETITLE, strTitle, _countof(strTitle));
4129e147beSKatayama Hirofumi MZ 
4229e147beSKatayama Hirofumi MZ     DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME;
4329e147beSKatayama Hirofumi MZ     return Create(hwndParent, rc, strTitle, style, WS_EX_PALETTEWINDOW);
4429e147beSKatayama Hirofumi MZ }
4529e147beSKatayama Hirofumi MZ 
OnMove(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)46bfd42c67SKatayama Hirofumi MZ LRESULT CMiniatureWindow::OnMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
47bfd42c67SKatayama Hirofumi MZ {
48bfd42c67SKatayama Hirofumi MZ     if (IsWindowVisible() && !IsIconic() && !IsZoomed())
49bfd42c67SKatayama Hirofumi MZ     {
50bfd42c67SKatayama Hirofumi MZ         CRect rc;
51bfd42c67SKatayama Hirofumi MZ         GetWindowRect(&rc);
52bfd42c67SKatayama Hirofumi MZ         registrySettings.ThumbXPos = rc.left;
53bfd42c67SKatayama Hirofumi MZ         registrySettings.ThumbYPos = rc.top;
54bfd42c67SKatayama Hirofumi MZ     }
55bfd42c67SKatayama Hirofumi MZ     return 0;
56bfd42c67SKatayama Hirofumi MZ }
57bfd42c67SKatayama Hirofumi MZ 
OnSize(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)58bfd42c67SKatayama Hirofumi MZ LRESULT CMiniatureWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
59bfd42c67SKatayama Hirofumi MZ {
60bfd42c67SKatayama Hirofumi MZ     if (IsWindowVisible() && !IsIconic() && !IsZoomed())
61bfd42c67SKatayama Hirofumi MZ     {
62bfd42c67SKatayama Hirofumi MZ         CRect rc;
63bfd42c67SKatayama Hirofumi MZ         GetWindowRect(&rc);
64bfd42c67SKatayama Hirofumi MZ         registrySettings.ThumbWidth = rc.Width();
65bfd42c67SKatayama Hirofumi MZ         registrySettings.ThumbHeight = rc.Height();
66bfd42c67SKatayama Hirofumi MZ     }
67bfd42c67SKatayama Hirofumi MZ     return 0;
68bfd42c67SKatayama Hirofumi MZ }
69bfd42c67SKatayama Hirofumi MZ 
OnClose(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)70c2c66affSColin Finck LRESULT CMiniatureWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
71c2c66affSColin Finck {
7229e147beSKatayama Hirofumi MZ     ShowWindow(SW_HIDE);
7329e147beSKatayama Hirofumi MZ     registrySettings.ShowThumbnail = FALSE;
74c2c66affSColin Finck     return 0;
75c2c66affSColin Finck }
76c2c66affSColin Finck 
OnEraseBkgnd(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)77bfd42c67SKatayama Hirofumi MZ LRESULT CMiniatureWindow::OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
78bfd42c67SKatayama Hirofumi MZ {
79bfd42c67SKatayama Hirofumi MZ     return TRUE; /* Avoid flickering */
80bfd42c67SKatayama Hirofumi MZ }
81bfd42c67SKatayama Hirofumi MZ 
OnPaint(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)82c2c66affSColin Finck LRESULT CMiniatureWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
83c2c66affSColin Finck {
8468e6820dSKatayama Hirofumi MZ     RECT rc;
8568e6820dSKatayama Hirofumi MZ     GetClientRect(&rc);
8668e6820dSKatayama Hirofumi MZ 
87bfd42c67SKatayama Hirofumi MZ     // Start painting
8868e6820dSKatayama Hirofumi MZ     PAINTSTRUCT ps;
8968e6820dSKatayama Hirofumi MZ     HDC hDC = BeginPaint(&ps);
90bfd42c67SKatayama Hirofumi MZ     if (!hDC)
91bfd42c67SKatayama Hirofumi MZ         return 0;
92bfd42c67SKatayama Hirofumi MZ 
93bfd42c67SKatayama Hirofumi MZ     // Use a memory bitmap to reduce flickering
94bfd42c67SKatayama Hirofumi MZ     HDC hdcMem = ::CreateCompatibleDC(hDC);
952f856f6fSKatayama Hirofumi MZ     m_hbmCached = CachedBufferDIB(m_hbmCached, rc.right, rc.bottom);
962f856f6fSKatayama Hirofumi MZ     HGDIOBJ hbmOld = ::SelectObject(hdcMem, m_hbmCached);
97bfd42c67SKatayama Hirofumi MZ 
98bfd42c67SKatayama Hirofumi MZ     // FIXME: Consider aspect ratio
99bfd42c67SKatayama Hirofumi MZ 
100bfd42c67SKatayama Hirofumi MZ     // Fill the background
101bfd42c67SKatayama Hirofumi MZ     ::FillRect(hdcMem, &rc, (HBRUSH)(COLOR_BTNFACE + 1));
102bfd42c67SKatayama Hirofumi MZ 
103bfd42c67SKatayama Hirofumi MZ     // Draw the image (hdcMem <-- imageModel)
104bfd42c67SKatayama Hirofumi MZ     int cxImage = imageModel.GetWidth();
105bfd42c67SKatayama Hirofumi MZ     int cyImage = imageModel.GetHeight();
106bfd42c67SKatayama Hirofumi MZ     ::StretchBlt(hdcMem, 0, 0, rc.right, rc.bottom,
107bfd42c67SKatayama Hirofumi MZ                  imageModel.GetDC(), 0, 0, cxImage, cyImage,
10868e6820dSKatayama Hirofumi MZ                  SRCCOPY);
109bfd42c67SKatayama Hirofumi MZ 
110bfd42c67SKatayama Hirofumi MZ     // Move the image (hDC <-- hdcMem)
111bfd42c67SKatayama Hirofumi MZ     ::BitBlt(hDC, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
112bfd42c67SKatayama Hirofumi MZ 
113bfd42c67SKatayama Hirofumi MZ     // Clean up
1142f856f6fSKatayama Hirofumi MZ     ::SelectObject(hdcMem, hbmOld);
115bfd42c67SKatayama Hirofumi MZ     ::DeleteDC(hdcMem);
116bfd42c67SKatayama Hirofumi MZ 
11768e6820dSKatayama Hirofumi MZ     EndPaint(&ps);
118c2c66affSColin Finck     return 0;
119c2c66affSColin Finck }
1205675604dSKatayama Hirofumi MZ 
OnGetMinMaxInfo(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)1215675604dSKatayama Hirofumi MZ LRESULT CMiniatureWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
1225675604dSKatayama Hirofumi MZ {
1235675604dSKatayama Hirofumi MZ     // Avoid too small
1245675604dSKatayama Hirofumi MZ     LPMINMAXINFO pInfo = (LPMINMAXINFO)lParam;
125*e5792200SKatayama Hirofumi MZ     pInfo->ptMinTrackSize = { 100, 75 };
1265675604dSKatayama Hirofumi MZ     return 0;
1275675604dSKatayama Hirofumi MZ }
128