[MSPAINT] Remove extra scrlClientWindow (#5162)

CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-03-17 07:28:42 +09:00 committed by GitHub
parent 41c30182d4
commit a88dcbd6c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 110 additions and 194 deletions

View file

@ -74,7 +74,6 @@ extern CToolBox toolBoxContainer;
extern CToolSettingsWindow toolSettingsWindow; extern CToolSettingsWindow toolSettingsWindow;
extern CPaletteWindow paletteWindow; extern CPaletteWindow paletteWindow;
extern CScrollboxWindow scrollboxWindow; extern CScrollboxWindow scrollboxWindow;
extern CScrollboxWindow scrlClientWindow;
extern CSelectionWindow selectionWindow; extern CSelectionWindow selectionWindow;
extern CImgAreaWindow imageArea; extern CImgAreaWindow imageArea;
extern CSizeboxWindow sizeboxLeftTop; extern CSizeboxWindow sizeboxLeftTop;

View file

@ -14,22 +14,6 @@
/* FUNCTIONS ********************************************************/ /* FUNCTIONS ********************************************************/
void
updateCanvasAndScrollbars()
{
selectionWindow.ShowWindow(SW_HIDE);
int zoomedWidth = Zoomed(imageModel.GetWidth());
int zoomedHeight = Zoomed(imageModel.GetHeight());
imageArea.MoveWindow(GRIP_SIZE, GRIP_SIZE, zoomedWidth, zoomedHeight, FALSE);
scrollboxWindow.Invalidate(TRUE);
imageArea.Invalidate(FALSE);
scrollboxWindow.SetScrollPos(SB_HORZ, 0, TRUE);
scrollboxWindow.SetScrollPos(SB_VERT, 0, TRUE);
}
void CImgAreaWindow::drawZoomFrame(int mouseX, int mouseY) void CImgAreaWindow::drawZoomFrame(int mouseX, int mouseY)
{ {
HDC hdc; HDC hdc;
@ -68,37 +52,9 @@ void CImgAreaWindow::drawZoomFrame(int mouseX, int mouseY)
LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
if (!IsWindow() || !sizeboxLeftTop.IsWindow()) if (!IsWindow())
return 0; return 0;
int imgXRes = imageModel.GetWidth(); UpdateScrollbox(NULL);
int imgYRes = imageModel.GetHeight();
sizeboxLeftTop.MoveWindow(
0,
0, GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxCenterTop.MoveWindow(
GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2,
0, GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightTop.MoveWindow(
GRIP_SIZE + Zoomed(imgXRes),
0, GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxLeftCenter.MoveWindow(
0,
GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightCenter.MoveWindow(
GRIP_SIZE + Zoomed(imgXRes),
GRIP_SIZE + (Zoomed(imgYRes) - GRIP_SIZE) / 2,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxLeftBottom.MoveWindow(
0,
GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxCenterBottom.MoveWindow(
GRIP_SIZE + (Zoomed(imgXRes) - GRIP_SIZE) / 2,
GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightBottom.MoveWindow(
GRIP_SIZE + Zoomed(imgXRes),
GRIP_SIZE + Zoomed(imgYRes), GRIP_SIZE, GRIP_SIZE, TRUE);
UpdateScrollbox();
return 0; return 0;
} }
@ -390,7 +346,7 @@ LRESULT CImgAreaWindow::OnMouseLeave(UINT nMsg, WPARAM wParam, LPARAM lParam, BO
LRESULT CImgAreaWindow::OnImageModelDimensionsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CImgAreaWindow::OnImageModelDimensionsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
updateCanvasAndScrollbars(); UpdateScrollbox(NULL);
return 0; return 0;
} }

View file

@ -61,7 +61,6 @@ CToolBox toolBoxContainer;
CToolSettingsWindow toolSettingsWindow; CToolSettingsWindow toolSettingsWindow;
CPaletteWindow paletteWindow; CPaletteWindow paletteWindow;
CScrollboxWindow scrollboxWindow; CScrollboxWindow scrollboxWindow;
CScrollboxWindow scrlClientWindow;
CSelectionWindow selectionWindow; CSelectionWindow selectionWindow;
CImgAreaWindow imageArea; CImgAreaWindow imageArea;
CSizeboxWindow sizeboxLeftTop; CSizeboxWindow sizeboxLeftTop;
@ -225,7 +224,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
paletteWindow.Create(hwnd, paletteWindowPos, NULL, WS_CHILD | WS_VISIBLE); paletteWindow.Create(hwnd, paletteWindowPos, NULL, WS_CHILD | WS_VISIBLE);
/* creating the scroll box */ /* creating the scroll box */
RECT scrollboxWindowPos = {56, 49, 56 + 472, 49 + 248}; RECT scrollboxWindowPos = {0, 0, 0 + 500, 0 + 500};
scrollboxWindow.Create(hwnd, scrollboxWindowPos, NULL, scrollboxWindow.Create(hwnd, scrollboxWindowPos, NULL,
WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, WS_EX_CLIENTEDGE); WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, WS_EX_CLIENTEDGE);
@ -237,16 +236,13 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
if (registrySettings.ShowStatusBar) if (registrySettings.ShowStatusBar)
ShowWindow(hStatusBar, SW_SHOWNOACTIVATE); ShowWindow(hStatusBar, SW_SHOWNOACTIVATE);
RECT scrlClientWindowPos = {0, 0, 0 + 500, 0 + 500}; // Creating the window inside the scroll box
scrlClientWindow.Create(scrollboxWindow.m_hWnd, scrlClientWindowPos, NULL, WS_CHILD | WS_VISIBLE); RECT imageAreaPos = {GRIP_SIZE, GRIP_SIZE, GRIP_SIZE + imageModel.GetWidth(), GRIP_SIZE + imageModel.GetHeight()};
imageArea.Create(scrollboxWindow.m_hWnd, imageAreaPos, NULL, WS_CHILD | WS_VISIBLE);
/* create selection window (initially hidden) */ /* create selection window (initially hidden) */
RECT selectionWindowPos = {350, 0, 350 + 100, 0 + 100}; RECT selectionWindowPos = {350, 0, 350 + 100, 0 + 100};
selectionWindow.Create(scrlClientWindow.m_hWnd, selectionWindowPos, NULL, WS_CHILD | BS_OWNERDRAW); selectionWindow.Create(imageArea.m_hWnd, selectionWindowPos, NULL, WS_CHILD | BS_OWNERDRAW);
/* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
RECT imageAreaPos = {GRIP_SIZE, GRIP_SIZE, GRIP_SIZE + imageModel.GetWidth(), GRIP_SIZE + imageModel.GetHeight()};
imageArea.Create(scrlClientWindow.m_hWnd, imageAreaPos, NULL, WS_CHILD | WS_VISIBLE);
if (__argc >= 2) if (__argc >= 2)
{ {
@ -312,14 +308,14 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
/* creating the size boxes */ /* creating the size boxes */
RECT sizeboxPos = {0, 0, GRIP_SIZE, GRIP_SIZE}; RECT sizeboxPos = {0, 0, GRIP_SIZE, GRIP_SIZE};
sizeboxLeftTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxLeftTop.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxCenterTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxCenterTop.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxRightTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxRightTop.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxLeftCenter.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxLeftCenter.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxRightCenter.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxRightCenter.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxLeftBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxLeftBottom.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxCenterBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxCenterBottom.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
sizeboxRightBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); sizeboxRightBottom.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE);
/* placing the size boxes around the image */ /* placing the size boxes around the image */
imageArea.SendMessage(WM_SIZE, 0, 0); imageArea.SendMessage(WM_SIZE, 0, 0);

View file

@ -11,108 +11,87 @@
#include "precomp.h" #include "precomp.h"
#include <atltypes.h> #include <atltypes.h>
/*
* Scrollbar functional modes:
* 0 view < canvas
* 1 view < canvas + scroll width
* 2 view >= canvas + scroll width
*
* Matrix of scrollbar presence (VERTICAL,HORIZONTAL) given by
* vertical & horizontal scrollbar modes (view:canvas ratio):
*
* horizontal mode
* | 0 | 1 | 2
* vertical ---+-------------+-------------+------------
* mode 0 | TRUE,TRUE | TRUE,TRUE | TRUE,FALSE
* ---+-------------+-------------+------------
* 1 | TRUE,TRUE | FALSE,FALSE | FALSE,FALSE
* ---+-------------+-------------+------------
* 2 | FALSE,TRUE | FALSE,FALSE | FALSE,FALSE
*/
struct ScrollbarPresence
{
BOOL bVert;
BOOL bHoriz;
};
CONST ScrollbarPresence sp_mx[3][3] =
{
{ { TRUE,TRUE }, { TRUE,TRUE }, { TRUE,FALSE } },
{ { TRUE,TRUE }, { FALSE,FALSE }, { FALSE,FALSE } },
{ { FALSE,TRUE }, { FALSE,FALSE }, { FALSE,FALSE } }
};
CONST INT HSCROLL_WIDTH = ::GetSystemMetrics(SM_CYHSCROLL);
CONST INT VSCROLL_WIDTH = ::GetSystemMetrics(SM_CXVSCROLL);
/* FUNCTIONS ********************************************************/ /* FUNCTIONS ********************************************************/
void void
UpdateScrollbox() UpdateScrollbox(HWND hwndFrom)
{ {
CRect tempRect; CRect tempRect;
CSize sizeImageArea; scrollboxWindow.GetClientRect(&tempRect);
CSize sizeScrollBox; CSize sizeScrollBox(tempRect.Width(), tempRect.Height());
INT vmode, hmode;
SCROLLINFO si;
scrollboxWindow.GetWindowRect(&tempRect); CSize sizeZoomed = { Zoomed(imageModel.GetWidth()), Zoomed(imageModel.GetHeight()) };
sizeScrollBox = CSize(tempRect.Width(), tempRect.Height()); CSize sizeWhole = { sizeZoomed.cx + (GRIP_SIZE * 2), sizeZoomed.cy + (GRIP_SIZE * 2) };
if (imageArea.IsWindow())
imageArea.GetClientRect(&tempRect);
sizeImageArea = CSize(tempRect.Width(), tempRect.Height());
sizeImageArea += CSize(GRIP_SIZE * 2, GRIP_SIZE * 2);
/* show/hide the scrollbars */ /* show/hide the scrollbars */
vmode = (sizeScrollBox.cy < sizeImageArea.cy ? 0 : scrollboxWindow.ShowScrollBar(SB_HORZ, sizeScrollBox.cx < sizeWhole.cx);
(sizeScrollBox.cy < sizeImageArea.cy + HSCROLL_WIDTH ? 1 : 2)); scrollboxWindow.ShowScrollBar(SB_VERT, sizeScrollBox.cy < sizeWhole.cy);
hmode = (sizeScrollBox.cx < sizeImageArea.cx ? 0 :
(sizeScrollBox.cx < sizeImageArea.cx + VSCROLL_WIDTH ? 1 : 2));
scrollboxWindow.ShowScrollBar(SB_VERT, sp_mx[vmode][hmode].bVert);
scrollboxWindow.ShowScrollBar(SB_HORZ, sp_mx[vmode][hmode].bHoriz);
si.cbSize = sizeof(SCROLLINFO); if (sizeScrollBox.cx < sizeWhole.cx || sizeScrollBox.cy < sizeWhole.cy)
si.fMask = SIF_PAGE | SIF_RANGE; {
scrollboxWindow.GetClientRect(&tempRect);
sizeScrollBox = CSize(tempRect.Width(), tempRect.Height());
}
SCROLLINFO si = { sizeof(si), SIF_PAGE | SIF_RANGE };
si.nMin = 0; si.nMin = 0;
si.nMax = sizeImageArea.cx + si.nMax = sizeWhole.cx;
(sp_mx[vmode][hmode].bVert == TRUE ? HSCROLL_WIDTH : 0);
si.nPage = sizeScrollBox.cx; si.nPage = sizeScrollBox.cx;
scrollboxWindow.SetScrollInfo(SB_HORZ, &si); scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
si.nMax = sizeImageArea.cy + si.nMax = sizeWhole.cy;
(sp_mx[vmode][hmode].bHoriz == TRUE ? VSCROLL_WIDTH : 0);
si.nPage = sizeScrollBox.cy; si.nPage = sizeScrollBox.cy;
scrollboxWindow.SetScrollInfo(SB_VERT, &si); scrollboxWindow.SetScrollInfo(SB_VERT, &si);
if (scrlClientWindow.IsWindow()) INT dx = -scrollboxWindow.GetScrollPos(SB_HORZ);
INT dy = -scrollboxWindow.GetScrollPos(SB_VERT);
if (sizeboxLeftTop.IsWindow())
{ {
scrlClientWindow.MoveWindow( sizeboxLeftTop.MoveWindow(dx, dy, GRIP_SIZE, GRIP_SIZE, TRUE);
-scrollboxWindow.GetScrollPos(SB_HORZ), -scrollboxWindow.GetScrollPos(SB_VERT), sizeboxCenterTop.MoveWindow(dx + GRIP_SIZE + (sizeZoomed.cx - GRIP_SIZE) / 2,
sizeImageArea.cx, sizeImageArea.cy, TRUE); dy,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightTop.MoveWindow(dx + GRIP_SIZE + sizeZoomed.cx,
dy,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxLeftCenter.MoveWindow(dx,
dy + GRIP_SIZE + (sizeZoomed.cy - GRIP_SIZE) / 2,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightCenter.MoveWindow(dx + GRIP_SIZE + sizeZoomed.cx,
dy + GRIP_SIZE + (sizeZoomed.cy - GRIP_SIZE) / 2,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxLeftBottom.MoveWindow(dx,
dy + GRIP_SIZE + sizeZoomed.cy,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxCenterBottom.MoveWindow(dx + GRIP_SIZE + (sizeZoomed.cx - GRIP_SIZE) / 2,
dy + GRIP_SIZE + sizeZoomed.cy,
GRIP_SIZE, GRIP_SIZE, TRUE);
sizeboxRightBottom.MoveWindow(dx + GRIP_SIZE + sizeZoomed.cx,
dy + GRIP_SIZE + sizeZoomed.cy,
GRIP_SIZE, GRIP_SIZE, TRUE);
} }
if (imageArea.IsWindow() && hwndFrom != imageArea.m_hWnd)
imageArea.MoveWindow(dx + GRIP_SIZE, dy + GRIP_SIZE, sizeZoomed.cx, sizeZoomed.cy, TRUE);
} }
LRESULT CScrollboxWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CScrollboxWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
if (m_hWnd && m_hWnd == scrollboxWindow.m_hWnd) if (m_hWnd)
{ {
UpdateScrollbox(); UpdateScrollbox(m_hWnd);
} }
return 0; return 0;
} }
LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
if (m_hWnd == scrollboxWindow.m_hWnd)
{
SCROLLINFO si; SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO); si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL; si.fMask = SIF_ALL;
scrollboxWindow.GetScrollInfo(SB_HORZ, &si); GetScrollInfo(SB_HORZ, &si);
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case SB_THUMBTRACK: case SB_THUMBTRACK:
@ -132,23 +111,17 @@ LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
si.nPos += si.nPage; si.nPos += si.nPage;
break; break;
} }
scrollboxWindow.SetScrollInfo(SB_HORZ, &si); SetScrollInfo(SB_HORZ, &si);
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ), UpdateScrollbox(m_hWnd);
-scrollboxWindow.GetScrollPos(SB_VERT),
Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE,
Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE);
}
return 0; return 0;
} }
LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
if (m_hWnd == scrollboxWindow.m_hWnd)
{
SCROLLINFO si; SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO); si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL; si.fMask = SIF_ALL;
scrollboxWindow.GetScrollInfo(SB_VERT, &si); GetScrollInfo(SB_VERT, &si);
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case SB_THUMBTRACK: case SB_THUMBTRACK:
@ -168,19 +141,13 @@ LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
si.nPos += si.nPage; si.nPos += si.nPage;
break; break;
} }
scrollboxWindow.SetScrollInfo(SB_VERT, &si); SetScrollInfo(SB_VERT, &si);
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ), UpdateScrollbox(m_hWnd);
-scrollboxWindow.GetScrollPos(SB_VERT),
Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE,
Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE);
}
return 0; return 0;
} }
LRESULT CScrollboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CScrollboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
selectionWindow.ShowWindow(SW_HIDE);
switch (toolsModel.GetActiveTool()) switch (toolsModel.GetActiveTool())
{ {
case TOOL_BEZIER: case TOOL_BEZIER:

View file

@ -28,4 +28,4 @@ public:
LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
}; };
void UpdateScrollbox(); void UpdateScrollbox(HWND hwndFrom);

View file

@ -107,8 +107,6 @@ LRESULT CSelectionWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam,
if (m_iAction != ACTION_MOVE) if (m_iAction != ACTION_MOVE)
SetCursor(LoadCursor(NULL, m_lpszCursorLUT[m_iAction])); SetCursor(LoadCursor(NULL, m_lpszCursorLUT[m_iAction]));
m_bMoving = TRUE; m_bMoving = TRUE;
scrlClientWindow.InvalidateRect(NULL, TRUE);
scrlClientWindow.SendMessage(WM_PAINT, 0, 0);
imageArea.InvalidateRect(NULL, FALSE); imageArea.InvalidateRect(NULL, FALSE);
imageArea.SendMessage(WM_PAINT, 0, 0); imageArea.SendMessage(WM_PAINT, 0, 0);
m_rgbBack = paletteModel.GetBgColor(); m_rgbBack = paletteModel.GetBgColor();