[MSPAINT_NEW] use the same hard-coded observer pattern for the SelectionModel (WIP)
authorBenedikt Freisen <b.freisen@gmx.net>
Thu, 9 Jul 2015 18:48:42 +0000 (18:48 +0000)
committerBenedikt Freisen <b.freisen@gmx.net>
Thu, 9 Jul 2015 18:48:42 +0000 (18:48 +0000)
svn path=/trunk/; revision=68383

reactos/base/applications/mspaint_new/definitions.h
reactos/base/applications/mspaint_new/palette.cpp
reactos/base/applications/mspaint_new/palettemodel.cpp
reactos/base/applications/mspaint_new/selection.cpp
reactos/base/applications/mspaint_new/selection.h
reactos/base/applications/mspaint_new/selectionmodel.cpp
reactos/base/applications/mspaint_new/selectionmodel.h
reactos/base/applications/mspaint_new/toolsettings.cpp
reactos/base/applications/mspaint_new/toolsmodel.cpp
reactos/base/applications/mspaint_new/winproc.cpp

index ce6e905..2155a6d 100644 (file)
 #define WM_PALETTEMODELPALETTECHANGED (WM_APP + 4)
 #define WM_IMAGEMODELDIMENSIONSCHANGED (WM_APP + 5)
 #define WM_IMAGEMODELIMAGECHANGED (WM_APP + 6)
+#define WM_SELECTIONMODELREFRESHNEEDED (WM_APP + 7)
index 72d5fbe..2e1c993 100644 (file)
@@ -61,22 +61,14 @@ LRESULT CPaletteWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b
 LRESULT CPaletteWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     if (GET_X_LPARAM(lParam) >= 31)
-    {
         paletteModel.SetFgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14));
-        if (toolsModel.GetActiveTool() == 10)
-            ForceRefreshSelectionContents();
-    }
     return 0;
 }
 
 LRESULT CPaletteWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     if (GET_X_LPARAM(lParam) >= 31)
-    {
         paletteModel.SetBgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14));
-        if (toolsModel.GetActiveTool() == 10)
-            ForceRefreshSelectionContents();
-    }
     return 0;
 }
 
@@ -88,8 +80,6 @@ LRESULT CPaletteWindow::OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam,
             paletteModel.SetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14,
                 choosecolor.rgbResult);
             paletteModel.SetFgColor(choosecolor.rgbResult);
-            if (toolsModel.GetActiveTool() == 10)
-                ForceRefreshSelectionContents();
         }
     return 0;
 }
@@ -102,8 +92,6 @@ LRESULT CPaletteWindow::OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam,
             paletteModel.SetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14,
                 choosecolor.rgbResult);
             paletteModel.SetBgColor(choosecolor.rgbResult);
-            if (toolsModel.GetActiveTool() == 10)
-                ForceRefreshSelectionContents();
         }
     return 0;
 }
index 5515970..93c63b0 100644 (file)
@@ -90,6 +90,7 @@ void PaletteModel::SetBgColor(int newColor)
 void PaletteModel::NotifyColorChanged()
 {
     paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
+    selectionWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
 }
 
 void PaletteModel::NotifyPaletteChanged()
index cd3df62..9066929 100644 (file)
@@ -229,3 +229,25 @@ LRESULT CSelectionWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, B
     }
     return 0;
 }
+
+LRESULT CSelectionWindow::OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if (toolsModel.GetActiveTool() == TOOL_TEXT)
+        ForceRefreshSelectionContents();
+    return 0;
+}
+
+LRESULT CSelectionWindow::OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if (toolsModel.GetActiveTool() == TOOL_FREESEL ||
+        toolsModel.GetActiveTool() == TOOL_RECTSEL ||
+        toolsModel.GetActiveTool() == TOOL_TEXT)
+        ForceRefreshSelectionContents();
+    return 0;
+}
+
+LRESULT CSelectionWindow::OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    ForceRefreshSelectionContents();
+    return 0;
+}
index bf42c0c..d4fe9f4 100644 (file)
@@ -20,6 +20,9 @@ public:
         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
         MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
         MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
+        MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged)
+        MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged)
+        MESSAGE_HANDLER(WM_SELECTIONMODELREFRESHNEEDED, OnSelectionModelRefreshNeeded)
     END_MSG_MAP()
 
     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -30,6 +33,9 @@ public:
     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 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);
 
 private:
     static const LPCTSTR m_lpszCursorLUT[9];
index 4ed7b07..af720fa 100644 (file)
@@ -183,6 +183,7 @@ void SelectionModel::FlipHorizontally()
     SelectObject(m_hDC, m_hBm);
     StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, 0, -RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), m_hDC,
                0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY);
+    NotifyRefreshNeeded();
 }
 
 void SelectionModel::FlipVertically()
@@ -193,6 +194,7 @@ void SelectionModel::FlipVertically()
     SelectObject(m_hDC, m_hBm);
     StretchBlt(m_hDC, 0, RECT_HEIGHT(m_rcDest) - 1, RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC,
                0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY);
+    NotifyRefreshNeeded();
 }
 
 void SelectionModel::RotateNTimes90Degrees(int iN)
@@ -206,6 +208,7 @@ void SelectionModel::RotateNTimes90Degrees(int iN)
         StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, RECT_HEIGHT(m_rcDest) - 1, -RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC,
                    0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY);
     }
+    NotifyRefreshNeeded();
 }
 
 HBITMAP SelectionModel::GetBitmap()
@@ -326,3 +329,8 @@ void SelectionModel::DrawTextToolText(HDC hDCImage, COLORREF crFg, COLORREF crBg
 {
     Text(hDCImage, m_rcDest.left, m_rcDest.top, m_rcDest.right, m_rcDest.bottom, crFg, crBg, textToolText, hfontTextFont, bBgTransparent);
 }
+
+void SelectionModel::NotifyRefreshNeeded()
+{
+    selectionWindow.SendMessage(WM_SELECTIONMODELREFRESHNEEDED);
+}
index a3de6dc..0fec331 100644 (file)
@@ -33,6 +33,7 @@ private:
 
 //     void NotifySelectionChanging();
 //     void NotifySelectionChanged();
+    void NotifyRefreshNeeded();
 
 public:
     SelectionModel();
index 7cd22af..8246d10 100644 (file)
@@ -188,11 +188,7 @@ LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lPar
         case TOOL_RECTSEL:
         case TOOL_TEXT:
             if ((y > 1) && (y < 64))
-            {
                 toolsModel.SetBackgroundTransparent((y - 2) / 31);
-
-                ForceRefreshSelectionContents();
-            }
             break;
         case TOOL_RUBBER:
             if ((y > 1) && (y < 62))
index 05682a3..e23e6c5 100644 (file)
@@ -122,6 +122,7 @@ void ToolsModel::NotifyToolChanged()
 void ToolsModel::NotifyToolSettingsChanged()
 {
     toolSettingsWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
+    selectionWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
 }
 
 void ToolsModel::NotifyZoomChanged()
index 6757174..e9c3884 100644 (file)
@@ -448,10 +448,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
             {
                 case 1: /* flip horizontally */
                     if (selectionWindow.IsWindowVisible())
-                    {
                         selectionModel.FlipHorizontally();
-                        ForceRefreshSelectionContents();
-                    }
                     else
                     {
                         imageModel.CopyPrevious();
@@ -462,10 +459,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
                     break;
                 case 2: /* flip vertically */
                     if (selectionWindow.IsWindowVisible())
-                    {
                         selectionModel.FlipVertically();
-                        ForceRefreshSelectionContents();
-                    }
                     else
                     {
                         imageModel.CopyPrevious();
@@ -478,10 +472,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
                     break;
                 case 4: /* rotate 180 degrees */
                     if (selectionWindow.IsWindowVisible())
-                    {
                         selectionModel.RotateNTimes90Degrees(2);
-                        ForceRefreshSelectionContents();
-                    }
                     else
                     {
                         imageModel.CopyPrevious();