diff --git a/base/applications/mspaint/globalvar.h b/base/applications/mspaint/globalvar.h index de01287c4da..6ffcfa0ea50 100644 --- a/base/applications/mspaint/globalvar.h +++ b/base/applications/mspaint/globalvar.h @@ -74,7 +74,6 @@ extern CToolBox toolBoxContainer; extern CToolSettingsWindow toolSettingsWindow; extern CPaletteWindow paletteWindow; extern CScrollboxWindow scrollboxWindow; -extern CScrollboxWindow scrlClientWindow; extern CSelectionWindow selectionWindow; extern CImgAreaWindow imageArea; extern CSizeboxWindow sizeboxLeftTop; diff --git a/base/applications/mspaint/imgarea.cpp b/base/applications/mspaint/imgarea.cpp index c0a5f832251..5f646da7411 100644 --- a/base/applications/mspaint/imgarea.cpp +++ b/base/applications/mspaint/imgarea.cpp @@ -14,22 +14,6 @@ /* 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) { HDC hdc; @@ -68,37 +52,9 @@ void CImgAreaWindow::drawZoomFrame(int mouseX, int mouseY) LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (!IsWindow() || !sizeboxLeftTop.IsWindow()) + if (!IsWindow()) return 0; - int imgXRes = imageModel.GetWidth(); - 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(); + UpdateScrollbox(NULL); 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) { - updateCanvasAndScrollbars(); + UpdateScrollbox(NULL); return 0; } diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp index 5ee34cd3240..525a4634b95 100644 --- a/base/applications/mspaint/main.cpp +++ b/base/applications/mspaint/main.cpp @@ -61,7 +61,6 @@ CToolBox toolBoxContainer; CToolSettingsWindow toolSettingsWindow; CPaletteWindow paletteWindow; CScrollboxWindow scrollboxWindow; -CScrollboxWindow scrlClientWindow; CSelectionWindow selectionWindow; CImgAreaWindow imageArea; CSizeboxWindow sizeboxLeftTop; @@ -225,7 +224,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument paletteWindow.Create(hwnd, paletteWindowPos, NULL, WS_CHILD | WS_VISIBLE); /* 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, 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) ShowWindow(hStatusBar, SW_SHOWNOACTIVATE); - RECT scrlClientWindowPos = {0, 0, 0 + 500, 0 + 500}; - scrlClientWindow.Create(scrollboxWindow.m_hWnd, scrlClientWindowPos, NULL, WS_CHILD | WS_VISIBLE); + // Creating the window inside the scroll box + 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) */ RECT selectionWindowPos = {350, 0, 350 + 100, 0 + 100}; - selectionWindow.Create(scrlClientWindow.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); + selectionWindow.Create(imageArea.m_hWnd, selectionWindowPos, NULL, WS_CHILD | BS_OWNERDRAW); if (__argc >= 2) { @@ -312,14 +308,14 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument /* creating the size boxes */ RECT sizeboxPos = {0, 0, GRIP_SIZE, GRIP_SIZE}; - sizeboxLeftTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); - sizeboxCenterTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); - sizeboxRightTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); - sizeboxLeftCenter.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); - sizeboxRightCenter.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); - sizeboxLeftBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); - sizeboxCenterBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); - sizeboxRightBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); + sizeboxLeftTop.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); + sizeboxCenterTop.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); + sizeboxRightTop.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); + sizeboxLeftCenter.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); + sizeboxRightCenter.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); + sizeboxLeftBottom.Create(scrollboxWindow.m_hWnd, sizeboxPos, NULL, WS_CHILD | WS_VISIBLE); + sizeboxCenterBottom.Create(scrollboxWindow.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 */ imageArea.SendMessage(WM_SIZE, 0, 0); diff --git a/base/applications/mspaint/scrollbox.cpp b/base/applications/mspaint/scrollbox.cpp index c05dffd5ec9..2d36711dcc4 100644 --- a/base/applications/mspaint/scrollbox.cpp +++ b/base/applications/mspaint/scrollbox.cpp @@ -11,176 +11,143 @@ #include "precomp.h" #include -/* - * 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 ********************************************************/ void -UpdateScrollbox() +UpdateScrollbox(HWND hwndFrom) { CRect tempRect; - CSize sizeImageArea; - CSize sizeScrollBox; - INT vmode, hmode; - SCROLLINFO si; + scrollboxWindow.GetClientRect(&tempRect); + CSize sizeScrollBox(tempRect.Width(), tempRect.Height()); - scrollboxWindow.GetWindowRect(&tempRect); - sizeScrollBox = CSize(tempRect.Width(), tempRect.Height()); - - if (imageArea.IsWindow()) - imageArea.GetClientRect(&tempRect); - sizeImageArea = CSize(tempRect.Width(), tempRect.Height()); - sizeImageArea += CSize(GRIP_SIZE * 2, GRIP_SIZE * 2); + CSize sizeZoomed = { Zoomed(imageModel.GetWidth()), Zoomed(imageModel.GetHeight()) }; + CSize sizeWhole = { sizeZoomed.cx + (GRIP_SIZE * 2), sizeZoomed.cy + (GRIP_SIZE * 2) }; /* show/hide the scrollbars */ - vmode = (sizeScrollBox.cy < sizeImageArea.cy ? 0 : - (sizeScrollBox.cy < sizeImageArea.cy + HSCROLL_WIDTH ? 1 : 2)); - 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); + scrollboxWindow.ShowScrollBar(SB_HORZ, sizeScrollBox.cx < sizeWhole.cx); + scrollboxWindow.ShowScrollBar(SB_VERT, sizeScrollBox.cy < sizeWhole.cy); - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_PAGE | SIF_RANGE; + if (sizeScrollBox.cx < sizeWhole.cx || sizeScrollBox.cy < sizeWhole.cy) + { + scrollboxWindow.GetClientRect(&tempRect); + sizeScrollBox = CSize(tempRect.Width(), tempRect.Height()); + } + + SCROLLINFO si = { sizeof(si), SIF_PAGE | SIF_RANGE }; si.nMin = 0; - si.nMax = sizeImageArea.cx + - (sp_mx[vmode][hmode].bVert == TRUE ? HSCROLL_WIDTH : 0); + si.nMax = sizeWhole.cx; si.nPage = sizeScrollBox.cx; scrollboxWindow.SetScrollInfo(SB_HORZ, &si); - si.nMax = sizeImageArea.cy + - (sp_mx[vmode][hmode].bHoriz == TRUE ? VSCROLL_WIDTH : 0); + si.nMax = sizeWhole.cy; si.nPage = sizeScrollBox.cy; 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( - -scrollboxWindow.GetScrollPos(SB_HORZ), -scrollboxWindow.GetScrollPos(SB_VERT), - sizeImageArea.cx, sizeImageArea.cy, TRUE); + sizeboxLeftTop.MoveWindow(dx, dy, GRIP_SIZE, GRIP_SIZE, TRUE); + sizeboxCenterTop.MoveWindow(dx + GRIP_SIZE + (sizeZoomed.cx - GRIP_SIZE) / 2, + 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) { - if (m_hWnd && m_hWnd == scrollboxWindow.m_hWnd) + if (m_hWnd) { - UpdateScrollbox(); + UpdateScrollbox(m_hWnd); } return 0; } LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (m_hWnd == scrollboxWindow.m_hWnd) + SCROLLINFO si; + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_ALL; + GetScrollInfo(SB_HORZ, &si); + switch (LOWORD(wParam)) { - SCROLLINFO si; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_ALL; - scrollboxWindow.GetScrollInfo(SB_HORZ, &si); - switch (LOWORD(wParam)) - { - case SB_THUMBTRACK: - case SB_THUMBPOSITION: - si.nPos = HIWORD(wParam); - break; - case SB_LINELEFT: - si.nPos -= 5; - break; - case SB_LINERIGHT: - si.nPos += 5; - break; - case SB_PAGELEFT: - si.nPos -= si.nPage; - break; - case SB_PAGERIGHT: - si.nPos += si.nPage; - break; - } - scrollboxWindow.SetScrollInfo(SB_HORZ, &si); - scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ), - -scrollboxWindow.GetScrollPos(SB_VERT), - Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE, - Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE); + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + si.nPos = HIWORD(wParam); + break; + case SB_LINELEFT: + si.nPos -= 5; + break; + case SB_LINERIGHT: + si.nPos += 5; + break; + case SB_PAGELEFT: + si.nPos -= si.nPage; + break; + case SB_PAGERIGHT: + si.nPos += si.nPage; + break; } + SetScrollInfo(SB_HORZ, &si); + UpdateScrollbox(m_hWnd); return 0; } LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (m_hWnd == scrollboxWindow.m_hWnd) + SCROLLINFO si; + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_ALL; + GetScrollInfo(SB_VERT, &si); + switch (LOWORD(wParam)) { - SCROLLINFO si; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_ALL; - scrollboxWindow.GetScrollInfo(SB_VERT, &si); - switch (LOWORD(wParam)) - { - case SB_THUMBTRACK: - case SB_THUMBPOSITION: - si.nPos = HIWORD(wParam); - break; - case SB_LINEUP: - si.nPos -= 5; - break; - case SB_LINEDOWN: - si.nPos += 5; - break; - case SB_PAGEUP: - si.nPos -= si.nPage; - break; - case SB_PAGEDOWN: - si.nPos += si.nPage; - break; - } - scrollboxWindow.SetScrollInfo(SB_VERT, &si); - scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ), - -scrollboxWindow.GetScrollPos(SB_VERT), - Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE, - Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE); + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + si.nPos = HIWORD(wParam); + break; + case SB_LINEUP: + si.nPos -= 5; + break; + case SB_LINEDOWN: + si.nPos += 5; + break; + case SB_PAGEUP: + si.nPos -= si.nPage; + break; + case SB_PAGEDOWN: + si.nPos += si.nPage; + break; } + SetScrollInfo(SB_VERT, &si); + UpdateScrollbox(m_hWnd); return 0; } LRESULT CScrollboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - selectionWindow.ShowWindow(SW_HIDE); - switch (toolsModel.GetActiveTool()) { case TOOL_BEZIER: diff --git a/base/applications/mspaint/scrollbox.h b/base/applications/mspaint/scrollbox.h index e2fa3461847..56822089bf6 100644 --- a/base/applications/mspaint/scrollbox.h +++ b/base/applications/mspaint/scrollbox.h @@ -28,4 +28,4 @@ public: LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); }; -void UpdateScrollbox(); +void UpdateScrollbox(HWND hwndFrom); diff --git a/base/applications/mspaint/selection.cpp b/base/applications/mspaint/selection.cpp index 3a87a21f19d..64d01538216 100644 --- a/base/applications/mspaint/selection.cpp +++ b/base/applications/mspaint/selection.cpp @@ -107,8 +107,6 @@ LRESULT CSelectionWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, if (m_iAction != ACTION_MOVE) SetCursor(LoadCursor(NULL, m_lpszCursorLUT[m_iAction])); m_bMoving = TRUE; - scrlClientWindow.InvalidateRect(NULL, TRUE); - scrlClientWindow.SendMessage(WM_PAINT, 0, 0); imageArea.InvalidateRect(NULL, FALSE); imageArea.SendMessage(WM_PAINT, 0, 0); m_rgbBack = paletteModel.GetBgColor();