https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1a90009bb9651d3c52777a8d356bb4392937be81

commit 1a90009bb9651d3c52777a8d356bb4392937be81
Author:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
AuthorDate: Thu Oct 5 20:01:41 2023 +0900
Commit:     GitHub <nore...@github.com>
CommitDate: Thu Oct 5 20:01:41 2023 +0900

    [MSPAINT] Update scroll info on loading file (#5761)
    
    The scroll info was not updated when the file is loading.
    - Rename CCanvasWindow::Update as CCanvasWindow::updateScrollInfo.
    - Update scroll info on ImageModel::NotifyImageChanged.
    - Improve ImageModel::ClearHistory.
    CORE-19094
---
 base/applications/mspaint/canvas.cpp  |  8 ++++----
 base/applications/mspaint/canvas.h    |  2 +-
 base/applications/mspaint/dib.cpp     |  6 ++++++
 base/applications/mspaint/history.cpp | 17 +++++++++++++++--
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/base/applications/mspaint/canvas.cpp 
b/base/applications/mspaint/canvas.cpp
index d62779f39a6..a4eeead446b 100644
--- a/base/applications/mspaint/canvas.cpp
+++ b/base/applications/mspaint/canvas.cpp
@@ -180,7 +180,7 @@ VOID CCanvasWindow::DoDraw(HDC hDC, RECT& rcClient, RECT& 
rcPaint)
     ::DeleteDC(hdcMem0);
 }
 
-VOID CCanvasWindow::Update(HWND hwndFrom)
+VOID CCanvasWindow::updateScrollInfo()
 {
     CRect rcClient;
     GetClientRect(&rcClient);
@@ -214,7 +214,7 @@ VOID CCanvasWindow::Update(HWND hwndFrom)
 LRESULT CCanvasWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& 
bHandled)
 {
     if (m_hWnd)
-        Update(m_hWnd);
+        updateScrollInfo();
 
     return 0;
 }
@@ -245,7 +245,7 @@ VOID CCanvasWindow::OnHVScroll(WPARAM wParam, INT fnBar)
             break;
     }
     SetScrollInfo(fnBar, &si);
-    Update(m_hWnd);
+    updateScrollInfo();
     Invalidate(FALSE); // FIXME: Flicker
 }
 
@@ -627,7 +627,7 @@ LRESULT CCanvasWindow::OnLRButtonUp(BOOL bLeftButton, UINT 
nMsg, WPARAM wParam,
 
     m_hitCanvasSizeBox = HIT_NONE;
     toolsModel.resetTool(); // resets the point-buffer of the polygon and 
bezier functions
-    Update(NULL);
+    updateScrollInfo();
     Invalidate(TRUE);
     return 0;
 }
diff --git a/base/applications/mspaint/canvas.h 
b/base/applications/mspaint/canvas.h
index db0e549837b..dc26707be24 100644
--- a/base/applications/mspaint/canvas.h
+++ b/base/applications/mspaint/canvas.h
@@ -42,7 +42,7 @@ public:
 
     VOID cancelDrawing();
     VOID finishDrawing();
-    VOID Update(HWND hwndFrom);
+    VOID updateScrollInfo();
 
     VOID ImageToCanvas(POINT& pt);
     VOID ImageToCanvas(RECT& rc);
diff --git a/base/applications/mspaint/dib.cpp 
b/base/applications/mspaint/dib.cpp
index cd069c9ef6f..9e7080e3da4 100644
--- a/base/applications/mspaint/dib.cpp
+++ b/base/applications/mspaint/dib.cpp
@@ -274,8 +274,14 @@ HBITMAP DoLoadImageFile(HWND hwnd, LPCWSTR name, BOOL 
fIsMainFile)
     CImageDx img;
     float xDpi = 0, yDpi = 0;
     HRESULT hr = img.LoadDx(name, &xDpi, &yDpi);
+    if (FAILED(hr) && fIsMainFile)
+    {
+        imageModel.ClearHistory();
+        hr = img.LoadDx(name, &xDpi, &yDpi);
+    }
     if (FAILED(hr))
     {
+        ATLTRACE("hr: 0x%08lX\n", hr);
         ShowError(IDS_LOADERRORTEXT, name);
         return NULL;
     }
diff --git a/base/applications/mspaint/history.cpp 
b/base/applications/mspaint/history.cpp
index 9e924b9e3db..05990df42b8 100644
--- a/base/applications/mspaint/history.cpp
+++ b/base/applications/mspaint/history.cpp
@@ -15,9 +15,13 @@ ImageModel imageModel;
 void ImageModel::NotifyImageChanged()
 {
     if (canvasWindow.IsWindow())
-        canvasWindow.Invalidate(FALSE);
+    {
+        canvasWindow.updateScrollInfo();
+        canvasWindow.Invalidate();
+    }
+
     if (miniature.IsWindow())
-        miniature.Invalidate(FALSE);
+        miniature.Invalidate();
 }
 
 ImageModel::ImageModel()
@@ -99,6 +103,15 @@ void ImageModel::ResetToPrevious()
 
 void ImageModel::ClearHistory()
 {
+    for (int i = 0; i < HISTORYSIZE; ++i)
+    {
+        if (m_hBms[i] && i != m_currInd)
+        {
+            ::DeleteObject(m_hBms[i]);
+            m_hBms[i] = NULL;
+        }
+    }
+
     m_undoSteps = 0;
     m_redoSteps = 0;
 }

Reply via email to