[MSPAINT]
authorBenedikt Freisen <b.freisen@gmx.net>
Thu, 27 Jul 2017 09:29:42 +0000 (09:29 +0000)
committerBenedikt Freisen <b.freisen@gmx.net>
Thu, 27 Jul 2017 09:29:42 +0000 (09:29 +0000)
- Enable drag cancellation -- patch by Katayama Hirofumi MZ

CORE-13395 #resolve

svn path=/trunk/; revision=75418

reactos/base/applications/mspaint/imgarea.cpp
reactos/base/applications/mspaint/imgarea.h
reactos/base/applications/mspaint/selection.cpp
reactos/base/applications/mspaint/selection.h
reactos/base/applications/mspaint/sizebox.cpp
reactos/base/applications/mspaint/sizebox.h
reactos/base/applications/mspaint/winproc.cpp

index bf8afea..dbf2035 100644 (file)
@@ -5,6 +5,7 @@
  * PURPOSE:     Window procedure of the main window and all children apart from
  *              hPalWin, hToolSettings and hSelection
  * PROGRAMMERS: Benedikt Freisen
  * PURPOSE:     Window procedure of the main window and all children apart from
  *              hPalWin, hToolSettings and hSelection
  * PROGRAMMERS: Benedikt Freisen
+ *              Katayama Hirofumi MZ
  */
 
 /* INCLUDES *********************************************************/
  */
 
 /* INCLUDES *********************************************************/
@@ -191,8 +192,6 @@ LRESULT CImgAreaWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
 {
     if (drawing)
     {
 {
     if (drawing)
     {
-        ReleaseCapture();
-        drawing = FALSE;
         endPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
                      paletteModel.GetBgColor());
         Invalidate(FALSE);
         endPaintingL(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
                      paletteModel.GetBgColor());
         Invalidate(FALSE);
@@ -205,15 +204,78 @@ LRESULT CImgAreaWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
         }
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
     }
         }
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
     }
+    drawing = FALSE;
+    ReleaseCapture();
     return 0;
 }
 
     return 0;
 }
 
-LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+void CImgAreaWindow::cancelDrawing()
+{
+    POINT pt;
+    switch (toolsModel.GetActiveTool())
+    {
+        case TOOL_FREESEL: case TOOL_RECTSEL:
+        case TOOL_TEXT: case TOOL_ZOOM: case TOOL_SHAPE:
+            imageModel.ResetToPrevious();
+            selectionModel.ResetPtStack();
+            pointSP = 0;
+            Invalidate(FALSE);
+            break;
+        default:
+            GetCursorPos(&pt);
+            ScreenToClient(&pt);
+            // FIXME: dirty hack
+            if (GetKeyState(VK_LBUTTON) < 0)
+            {
+                endPaintingL(imageModel.GetDC(), pt.x * 1000 / toolsModel.GetZoom(), pt.y * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
+                             paletteModel.GetBgColor());
+            }
+            else if (GetKeyState(VK_RBUTTON) < 0)
+            {
+                endPaintingR(imageModel.GetDC(), pt.x * 1000 / toolsModel.GetZoom(), pt.y * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
+                             paletteModel.GetBgColor());
+            }
+            imageModel.Undo();
+            pointSP = 0;
+            selectionModel.ResetPtStack();
+    }
+}
+
+LRESULT CImgAreaWindow::OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     if (drawing)
     {
 {
     if (drawing)
     {
-        ReleaseCapture();
+        cancelDrawing();
         drawing = FALSE;
         drawing = FALSE;
+    }
+    return 0;
+}
+
+LRESULT CImgAreaWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if (wParam == VK_ESCAPE)
+    {
+        if (GetCapture() == m_hWnd)
+        {
+            ReleaseCapture();
+        }
+        else
+        {
+            switch (toolsModel.GetActiveTool())
+            {
+                case TOOL_SHAPE: case TOOL_BEZIER:
+                    cancelDrawing();
+                    break;
+            }
+        }
+    }
+    return 0;
+}
+
+LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if (drawing)
+    {
         endPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
                      paletteModel.GetBgColor());
         Invalidate(FALSE);
         endPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(),
                      paletteModel.GetBgColor());
         Invalidate(FALSE);
@@ -226,6 +288,8 @@ LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
         }
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
     }
         }
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
     }
+    ReleaseCapture();
+    drawing = FALSE;
     return 0;
 }
 
     return 0;
 }
 
index febe98e..79cc13d 100644 (file)
@@ -5,6 +5,7 @@
  * PURPOSE:     Window procedure of the main window and all children apart from
  *              hPalWin, hToolSettings and hSelection
  * PROGRAMMERS: Benedikt Freisen
  * PURPOSE:     Window procedure of the main window and all children apart from
  *              hPalWin, hToolSettings and hSelection
  * PROGRAMMERS: Benedikt Freisen
+ *              Katayama Hirofumi MZ
  */
 
 class CImgAreaWindow : public CWindowImpl<CMainWindow>
  */
 
 class CImgAreaWindow : public CWindowImpl<CMainWindow>
@@ -24,6 +25,8 @@ public:
         MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave)
         MESSAGE_HANDLER(WM_IMAGEMODELDIMENSIONSCHANGED, OnImageModelDimensionsChanged)
         MESSAGE_HANDLER(WM_IMAGEMODELIMAGECHANGED, OnImageModelImageChanged)
         MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave)
         MESSAGE_HANDLER(WM_IMAGEMODELDIMENSIONSCHANGED, OnImageModelDimensionsChanged)
         MESSAGE_HANDLER(WM_IMAGEMODELIMAGECHANGED, OnImageModelImageChanged)
+        MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
+        MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
     END_MSG_MAP()
 
     BOOL drawing;
     END_MSG_MAP()
 
     BOOL drawing;
@@ -40,6 +43,9 @@ private:
     LRESULT OnMouseLeave(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnImageModelDimensionsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnImageModelImageChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnMouseLeave(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnImageModelDimensionsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnImageModelImageChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
     void drawZoomFrame(int mouseX, int mouseY);
 
     void drawZoomFrame(int mouseX, int mouseY);
+    void cancelDrawing();
 };
 };
index a9e7530..9e5c689 100644 (file)
@@ -4,6 +4,7 @@
  * FILE:        base/applications/mspaint/selection.cpp
  * PURPOSE:     Window procedure of the selection window
  * PROGRAMMERS: Benedikt Freisen
  * FILE:        base/applications/mspaint/selection.cpp
  * PURPOSE:     Window procedure of the selection window
  * PROGRAMMERS: Benedikt Freisen
+ *              Katayama Hirofumi MZ
  */
 
 /* INCLUDES *********************************************************/
  */
 
 /* INCLUDES *********************************************************/
@@ -230,6 +231,39 @@ LRESULT CSelectionWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, B
     return 0;
 }
 
     return 0;
 }
 
+LRESULT CSelectionWindow::OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if (m_bMoving)
+    {
+        m_bMoving = FALSE;
+        if (m_iAction == ACTION_MOVE)
+        {
+            // FIXME: dirty hack
+            placeSelWin();
+            imageModel.Undo();
+            imageModel.Undo();
+        }
+        else
+        {
+            m_iAction = ACTION_MOVE;
+        }
+        ShowWindow(SW_HIDE);
+    }
+    return 0;
+}
+
+LRESULT CSelectionWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if (wParam == VK_ESCAPE)
+    {
+        if (GetCapture() == m_hWnd)
+        {
+            ReleaseCapture();
+        }
+    }
+    return 0;
+}
+
 LRESULT CSelectionWindow::OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     if (toolsModel.GetActiveTool() == TOOL_TEXT)
 LRESULT CSelectionWindow::OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     if (toolsModel.GetActiveTool() == TOOL_TEXT)
index 3f164b3..e2dacf2 100644 (file)
@@ -4,6 +4,7 @@
  * FILE:        base/applications/mspaint/selection.h
  * PURPOSE:     Window procedure of the selection window
  * PROGRAMMERS: Benedikt Freisen
  * FILE:        base/applications/mspaint/selection.h
  * PURPOSE:     Window procedure of the selection window
  * PROGRAMMERS: Benedikt Freisen
+ *              Katayama Hirofumi MZ
  */
 
 class CSelectionWindow : public CWindowImpl<CSelectionWindow>
  */
 
 class CSelectionWindow : public CWindowImpl<CSelectionWindow>
@@ -23,6 +24,8 @@ public:
         MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged)
         MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged)
         MESSAGE_HANDLER(WM_SELECTIONMODELREFRESHNEEDED, OnSelectionModelRefreshNeeded)
         MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged)
         MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged)
         MESSAGE_HANDLER(WM_SELECTIONMODELREFRESHNEEDED, OnSelectionModelRefreshNeeded)
+        MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
+        MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
     END_MSG_MAP()
 
     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     END_MSG_MAP()
 
     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -36,6 +39,8 @@ public:
     LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
 private:
     static const LPCTSTR m_lpszCursorLUT[9];
 
 private:
     static const LPCTSTR m_lpszCursorLUT[9];
index b5709d8..71fcb6a 100644 (file)
@@ -4,6 +4,7 @@
  * FILE:        base/applications/mspaint/sizebox.cpp
  * PURPOSE:     Window procedure of the size boxes
  * PROGRAMMERS: Benedikt Freisen
  * FILE:        base/applications/mspaint/sizebox.cpp
  * PURPOSE:     Window procedure of the size boxes
  * PROGRAMMERS: Benedikt Freisen
+ *              Katayama Hirofumi MZ
  */
 
 /* INCLUDES *********************************************************/
  */
 
 /* INCLUDES *********************************************************/
@@ -98,13 +99,25 @@ LRESULT CSizeboxWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
             imageModel.Crop(imgXRes + xRel, imgYRes + yRel, 0, 0);
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T(""));
     }
             imageModel.Crop(imgXRes + xRel, imgYRes + yRel, 0, 0);
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) _T(""));
     }
-    ReleaseCapture();
     resizing = FALSE;
     resizing = FALSE;
+    ReleaseCapture();
     return 0;
 }
 
     return 0;
 }
 
-LRESULT CSizeboxWindow::OnCancelMode(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+LRESULT CSizeboxWindow::OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     resizing = FALSE;
     return 0;
 }
 {
     resizing = FALSE;
     return 0;
 }
+
+LRESULT CSizeboxWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if (wParam == VK_ESCAPE)
+    {
+        if (GetCapture() == m_hWnd)
+        {
+            ReleaseCapture();
+        }
+    }
+    return 0;
+}
index c2624f7..afe89ba 100644 (file)
@@ -4,6 +4,7 @@
  * FILE:        base/applications/mspaint/sizebox.h
  * PURPOSE:     Window procedure of the size boxes
  * PROGRAMMERS: Benedikt Freisen
  * FILE:        base/applications/mspaint/sizebox.h
  * PURPOSE:     Window procedure of the size boxes
  * PROGRAMMERS: Benedikt Freisen
+ *              Katayama Hirofumi MZ
  */
 
 class CSizeboxWindow : public CWindowImpl<CSizeboxWindow>
  */
 
 class CSizeboxWindow : public CWindowImpl<CSizeboxWindow>
@@ -16,12 +17,14 @@ public:
         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
         MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
         MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
         MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
         MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
-        MESSAGE_HANDLER(WM_CANCELMODE, OnCancelMode)
+        MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
+        MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
     END_MSG_MAP()
 
     LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     END_MSG_MAP()
 
     LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
-    LRESULT OnCancelMode(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 };
 };
index e35f93e..ace8c96 100644 (file)
@@ -5,6 +5,7 @@
  * PURPOSE:     Window procedure of the main window and all children apart from
  *              hPalWin, hToolSettings and hSelection
  * PROGRAMMERS: Benedikt Freisen
  * PURPOSE:     Window procedure of the main window and all children apart from
  *              hPalWin, hToolSettings and hSelection
  * PROGRAMMERS: Benedikt Freisen
+ *              Katayama Hirofumi MZ
  */
 
 /* INCLUDES *********************************************************/
  */
 
 /* INCLUDES *********************************************************/
@@ -333,18 +334,33 @@ LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
 {
     if (wParam == VK_ESCAPE)
     {
 {
     if (wParam == VK_ESCAPE)
     {
-        if (!imageArea.drawing)
+        HWND hwndCapture = GetCapture();
+        if (hwndCapture)
         {
         {
-            /* Deselect */
-            if ((toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL))
+            if (selectionWindow.m_hWnd == hwndCapture ||
+                imageArea.m_hWnd == hwndCapture ||
+                fullscreenWindow.m_hWnd == hwndCapture ||
+                sizeboxLeftTop.m_hWnd == hwndCapture ||
+                sizeboxCenterTop.m_hWnd == hwndCapture ||
+                sizeboxRightTop.m_hWnd == hwndCapture ||
+                sizeboxLeftCenter.m_hWnd == hwndCapture ||
+                sizeboxRightCenter.m_hWnd == hwndCapture ||
+                sizeboxLeftBottom.m_hWnd == hwndCapture ||
+                sizeboxCenterBottom.m_hWnd == hwndCapture ||
+                sizeboxRightBottom.m_hWnd == hwndCapture)
             {
             {
-                startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
-                whilePaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
-                endPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
-                selectionWindow.ShowWindow(SW_HIDE);
+                SendMessage(hwndCapture, nMsg, wParam, lParam);
+            }
+        }
+        else
+        {
+            switch (toolsModel.GetActiveTool())
+            {
+                case TOOL_SHAPE: case TOOL_BEZIER:
+                    imageArea.SendMessage(nMsg, wParam, lParam);
+                    break;
             }
         }
             }
         }
-        /* FIXME: also cancel current drawing underway */
     }
     return 0;
 }
     }
     return 0;
 }