[MSPAINT_NEW] further ATLification, hard-coded observer pattern, minor cleanup (fourt...
authorBenedikt Freisen <b.freisen@gmx.net>
Tue, 7 Jul 2015 11:44:50 +0000 (11:44 +0000)
committerBenedikt Freisen <b.freisen@gmx.net>
Tue, 7 Jul 2015 11:44:50 +0000 (11:44 +0000)
svn path=/trunk/; revision=68370

25 files changed:
reactos/base/applications/mspaint_new/CMakeLists.txt
reactos/base/applications/mspaint_new/definitions.h
reactos/base/applications/mspaint_new/globalvar.h
reactos/base/applications/mspaint_new/imgarea.cpp
reactos/base/applications/mspaint_new/imgarea.h
reactos/base/applications/mspaint_new/main.cpp
reactos/base/applications/mspaint_new/miniature.h
reactos/base/applications/mspaint_new/palette.cpp
reactos/base/applications/mspaint_new/palette.h
reactos/base/applications/mspaint_new/palettemodel.cpp
reactos/base/applications/mspaint_new/palettemodel.h
reactos/base/applications/mspaint_new/precomp.h
reactos/base/applications/mspaint_new/scrollbox.h
reactos/base/applications/mspaint_new/selection.h
reactos/base/applications/mspaint_new/sizebox.h
reactos/base/applications/mspaint_new/textedit.cpp
reactos/base/applications/mspaint_new/textedit.h
reactos/base/applications/mspaint_new/toolbox.cpp [new file with mode: 0644]
reactos/base/applications/mspaint_new/toolbox.h [new file with mode: 0644]
reactos/base/applications/mspaint_new/toolsettings.cpp
reactos/base/applications/mspaint_new/toolsettings.h
reactos/base/applications/mspaint_new/toolsmodel.cpp
reactos/base/applications/mspaint_new/toolsmodel.h
reactos/base/applications/mspaint_new/winproc.cpp
reactos/base/applications/mspaint_new/winproc.h

index 5bab2d0..377f70d 100644 (file)
@@ -20,6 +20,7 @@ list(APPEND SOURCE
     selection.cpp
     sizebox.cpp
     textedit.cpp
+    toolbox.cpp
     toolsettings.cpp
     toolsmodel.cpp
     winproc.cpp
index f2dfc23..1871fdd 100644 (file)
 #define IDS_ANGLE      932
 
 #define IDS_LOADERRORTEXT 933
+
+#define WM_TOOLSMODELTOOLCHANGED WM_APP
+#define WM_TOOLSMODELSETTINGSCHANGED (WM_APP + 1)
+#define WM_TOOLSMODELZOOMCHANGED (WM_APP + 2)
+#define WM_PALETTEMODELCOLORCHANGED (WM_APP + 3)
+#define WM_PALETTEMODELPALETTECHANGED (WM_APP + 4)
index dbcdd3c..0e56a17 100644 (file)
@@ -58,7 +58,6 @@ class PaletteModel;
 extern PaletteModel paletteModel;
 
 extern HWND hStatusBar;
-extern HWND hTrackbarZoom;
 extern CHOOSECOLOR choosecolor;
 extern OPENFILENAME ofn;
 extern OPENFILENAME sfn;
@@ -88,6 +87,7 @@ extern BOOL showMiniature;
 
 class CMainWindow;
 class CMiniatureWindow;
+class CToolBox;
 class CToolSettingsWindow;
 class CPaletteWindow;
 class CScrollboxWindow;
@@ -98,7 +98,7 @@ class CTextEditWindow;
 
 extern CMainWindow mainWindow;
 extern CMiniatureWindow miniature;
-extern CMainWindow toolBoxContainer;
+extern CToolBox toolBoxContainer;
 extern CToolSettingsWindow toolSettingsWindow;
 extern CPaletteWindow paletteWindow;
 extern CScrollboxWindow scrollboxWindow;
index 4c04044..922c3e6 100644 (file)
@@ -187,7 +187,6 @@ LRESULT CImgAreaWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
                 GetPixel(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom());
             if (tempColor != CLR_INVALID)
                 paletteModel.SetFgColor(tempColor);
-            paletteWindow.Invalidate(FALSE);
         }
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
     }
@@ -209,7 +208,6 @@ LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
                 GetPixel(hDrawingDC, GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom());
             if (tempColor != CLR_INVALID)
                 paletteModel.SetBgColor(tempColor);
-            paletteWindow.Invalidate(FALSE);
         }
         SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) "");
     }
index 8cca59b..527b667 100644 (file)
@@ -12,7 +12,7 @@ class CImgAreaWindow : public CWindowImpl<CMainWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("ImgAreaWindow"), CS_DBLCLKS, COLOR_BTNFACE)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CImgAreaWindow)
         MESSAGE_HANDLER(WM_SIZE, OnSize)
         MESSAGE_HANDLER(WM_PAINT, OnPaint)
         MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
index afd1f46..d0d3ed0 100644 (file)
@@ -48,7 +48,6 @@ int textToolTextMaxLen = 0;
 PaletteModel paletteModel;
 
 HWND hStatusBar;
-HWND hTrackbarZoom;
 CHOOSECOLOR choosecolor;
 OPENFILENAME ofn;
 OPENFILENAME sfn;
@@ -78,7 +77,7 @@ BOOL showMiniature = FALSE;
 
 CMainWindow mainWindow;
 CMiniatureWindow miniature;
-CMainWindow toolBoxContainer;
+CToolBox toolBoxContainer;
 CToolSettingsWindow toolSettingsWindow;
 CPaletteWindow paletteWindow;
 CScrollboxWindow scrollboxWindow;
@@ -106,12 +105,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
     TCHAR progtitle[1000];
     TCHAR resstr[100];
     HMENU menu;
-    HWND hToolbar;
-    HIMAGELIST hImageList;
     HANDLE haccel;
-    HBITMAP tempBm;
-    int i;
-    TCHAR tooltips[16][30];
     HDC hDC;
 
     TCHAR *c;
@@ -155,11 +149,11 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
 
     /* create main window */
     RECT mainWindowPos = {0, 0, 544, 375};     // FIXME: use equivalent of CW_USEDEFAULT for position
-    hwnd = mainWindow.Create(HWND_DESKTOP, mainWindowPos, progtitle, WS_OVERLAPPEDWINDOW, 0, 0U, NULL);
+    hwnd = mainWindow.Create(HWND_DESKTOP, mainWindowPos, progtitle, WS_OVERLAPPEDWINDOW);
 
     RECT miniaturePos = {180, 200, 180 + 120, 200 + 100};
     miniature.Create(hwnd, miniaturePos, miniaturetitle,
-                     WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, WS_EX_PALETTEWINDOW, 0U, NULL);
+                     WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, WS_EX_PALETTEWINDOW);
 
     /* loading and setting the window menu from resource */
     menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
@@ -178,85 +172,40 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
     hCurPen      = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_PEN));
     hCurAirbrush = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_AIRBRUSH));
 
-    CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, 0, 0, 5000, 2, hwnd, NULL,
+    CreateWindowEx(0, _T("STATIC"), NULL, WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, 0, 0, 5000, 2, hwnd, NULL,
                    hThisInstance, NULL);
 
     RECT toolBoxContainerPos = {2, 2, 2 + 52, 2 + 350};
-    toolBoxContainer.Create(hwnd, toolBoxContainerPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    /* creating the 16 bitmap radio buttons and setting the bitmap */
-
-
-    /*
-     * FIXME: Unintentionally there is a line above the tool bar (hidden by y-offset).
-     * To prevent cropping of the buttons height has been increased from 200 to 205
-     */
-    hToolbar =
-        CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
-                       WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS,
-                       1, -2, 50, 205, toolBoxContainer.m_hWnd, NULL, hThisInstance, NULL);
-    hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
-    SendMessage(hToolbar, TB_SETIMAGELIST, 0, (LPARAM) hImageList);
-    tempBm = (HBITMAP) LoadImage(hThisInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0);
-    ImageList_AddMasked(hImageList, tempBm, 0xff00ff);
-    DeleteObject(tempBm);
-    SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
-
-    for(i = 0; i < 16; i++)
-    {
-        TBBUTTON tbbutton;
-        int wrapnow = 0;
-
-        if (i % 2 == 1)
-            wrapnow = TBSTATE_WRAP;
-
-        LoadString(hThisInstance, IDS_TOOLTIP1 + i, tooltips[i], 30);
-        ZeroMemory(&tbbutton, sizeof(TBBUTTON));
-        tbbutton.iString   = (INT_PTR) tooltips[i];
-        tbbutton.fsStyle   = TBSTYLE_CHECKGROUP;
-        tbbutton.fsState   = TBSTATE_ENABLED | wrapnow;
-        tbbutton.idCommand = ID_FREESEL + i;
-        tbbutton.iBitmap   = i;
-        SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
-    }
-
-    SendMessage(hToolbar, TB_CHECKBUTTON, ID_PEN, MAKELONG(TRUE, 0));
-    SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0);
-    SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25));
-
+    toolBoxContainer.Create(hwnd, toolBoxContainerPos, NULL, WS_CHILD | WS_VISIBLE);
     /* creating the tool settings child window */
     RECT toolSettingsWindowPos = {5, 208, 5 + 42, 208 + 140};
-    toolSettingsWindow.Create(toolBoxContainer.m_hWnd, toolSettingsWindowPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    hTrackbarZoom =
-        CreateWindowEx(0, TRACKBAR_CLASS, _T(""), WS_CHILD | TBS_VERT | TBS_AUTOTICKS, 1, 1, 40, 64,
-                       toolSettingsWindow.m_hWnd, NULL, hThisInstance, NULL);
-    SendMessage(hTrackbarZoom, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6));
-    SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 3);
+    toolSettingsWindow.Create(toolBoxContainer.m_hWnd, toolSettingsWindowPos, NULL, WS_CHILD | WS_VISIBLE);
 
     /* creating the palette child window */
     RECT paletteWindowPos = {56, 9, 56 + 255, 9 + 32};
-    paletteWindow.Create(hwnd, paletteWindowPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
+    paletteWindow.Create(hwnd, paletteWindowPos, NULL, WS_CHILD | WS_VISIBLE);
 
     /* creating the scroll box */
     RECT scrollboxWindowPos = {56, 49, 56 + 472, 49 + 248};
-    scrollboxWindow.Create(hwnd, scrollboxWindowPos, _T(""),
-                           WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, WS_EX_CLIENTEDGE, 0U, NULL);
+    scrollboxWindow.Create(hwnd, scrollboxWindowPos, NULL,
+                           WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, WS_EX_CLIENTEDGE);
 
     /* creating the status bar */
     hStatusBar =
-        CreateWindowEx(0, STATUSCLASSNAME, _T(""), SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd,
+        CreateWindowEx(0, STATUSCLASSNAME, NULL, SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd,
                        NULL, hThisInstance, NULL);
     SendMessage(hStatusBar, SB_SETMINHEIGHT, 21, 0);
 
     RECT scrlClientWindowPos = {0, 0, 0 + 500, 0 + 500};
-    scrlClientWindow.Create(scrollboxWindow.m_hWnd, scrlClientWindowPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
+    scrlClientWindow.Create(scrollboxWindow.m_hWnd, scrlClientWindowPos, NULL, WS_CHILD | WS_VISIBLE);
 
     /* create selection window (initially hidden) */
     RECT selectionWindowPos = {350, 0, 350 + 100, 0 + 100};
-    selectionWindow.Create(scrlClientWindow.m_hWnd, selectionWindowPos, _T(""), WS_CHILD | BS_OWNERDRAW, 0, 0U, NULL);
+    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 = {3, 3, 3 + imgXRes, 3 + imgYRes};
-    imageArea.Create(scrlClientWindow.m_hWnd, imageAreaPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
+    imageArea.Create(scrlClientWindow.m_hWnd, imageAreaPos, NULL, WS_CHILD | WS_VISIBLE);
 
     hDC = imageArea.GetDC();
     hDrawingDC = CreateCompatibleDC(hDC);
@@ -339,14 +288,14 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
 
     /* creating the size boxes */
     RECT sizeboxPos = {0, 0, 0 + 3, 0 + 3};
-    sizeboxLeftTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    sizeboxCenterTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    sizeboxRightTop.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    sizeboxLeftCenter.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    sizeboxRightCenter.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    sizeboxLeftBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    sizeboxCenterBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
-    sizeboxRightBottom.Create(scrlClientWindow.m_hWnd, sizeboxPos, _T(""), WS_CHILD | WS_VISIBLE, 0, 0U, NULL);
+    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);
     /* placing the size boxes around the image */
     imageArea.SendMessage(WM_SIZE, 0, 0);
 
@@ -355,12 +304,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
 
     /* creating the text editor window for the text tool */
     RECT textEditWindowPos = {300, 0, 300 + 300, 0 + 200};
-    textEditWindow.Create(hwnd, textEditWindowPos, _T(""), WS_OVERLAPPEDWINDOW, 0, 0U, NULL);
-    /* creating the edit control within the editor window */
-    hwndEditCtl =
-        CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""),
-                       WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
-                       0, 0, 100, 100, textEditWindow.m_hWnd, NULL, hThisInstance, NULL);
+    textEditWindow.Create(hwnd, textEditWindowPos, NULL, WS_OVERLAPPEDWINDOW);
 
     /* Make the window visible on the screen */
     ShowWindow (hwnd, nFunsterStil);
index e42dc3e..00033ed 100644 (file)
@@ -12,7 +12,7 @@ class CMiniatureWindow : public CWindowImpl<CMiniatureWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("MiniatureWindow"), CS_DBLCLKS, COLOR_BTNFACE)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CMiniatureWindow)
         MESSAGE_HANDLER(WM_CLOSE, OnClose)
         MESSAGE_HANDLER(WM_PAINT, OnPaint)
         MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
index f209c59..72d5fbe 100644 (file)
@@ -63,7 +63,6 @@ LRESULT CPaletteWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, B
     if (GET_X_LPARAM(lParam) >= 31)
     {
         paletteModel.SetFgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14));
-        InvalidateRect(NULL, FALSE);
         if (toolsModel.GetActiveTool() == 10)
             ForceRefreshSelectionContents();
     }
@@ -75,7 +74,6 @@ LRESULT CPaletteWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, B
     if (GET_X_LPARAM(lParam) >= 31)
     {
         paletteModel.SetBgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14));
-        InvalidateRect(NULL, FALSE);
         if (toolsModel.GetActiveTool() == 10)
             ForceRefreshSelectionContents();
     }
@@ -90,7 +88,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);
-            InvalidateRect(NULL, FALSE);
             if (toolsModel.GetActiveTool() == 10)
                 ForceRefreshSelectionContents();
         }
@@ -105,9 +102,20 @@ 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);
-            InvalidateRect(NULL, FALSE);
             if (toolsModel.GetActiveTool() == 10)
                 ForceRefreshSelectionContents();
         }
     return 0;
 }
+
+LRESULT CPaletteWindow::OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    InvalidateRect(NULL, FALSE);
+    return 0;
+}
+
+LRESULT CPaletteWindow::OnPaletteModelPaletteChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    InvalidateRect(NULL, FALSE);
+    return 0;
+}
index ddecbda..9d5caef 100644 (file)
@@ -17,6 +17,8 @@ public:
         MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
         MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk)
         MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnRButtonDblClk)
+        MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged)
+        MESSAGE_HANDLER(WM_PALETTEMODELPALETTECHANGED, OnPaletteModelPaletteChanged)
     END_MSG_MAP()
 
     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -24,4 +26,6 @@ public:
     LRESULT OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnPaletteModelPaletteChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 };
index b1c23f3..5515970 100644 (file)
@@ -45,6 +45,7 @@ void PaletteModel::SelectPalette(int nPalette)
     else
         return;
     m_nSelectedPalette = nPalette;
+    NotifyPaletteChanged();
 }
 
 int PaletteModel::GetColor(int nIndex)
@@ -58,7 +59,10 @@ int PaletteModel::GetColor(int nIndex)
 void PaletteModel::SetColor(int nIndex, int newColor)
 {
     if (nIndex < 28)
+    {
         m_colors[nIndex] = newColor;
+        NotifyPaletteChanged();
+    }
 }
 
 int PaletteModel::GetFgColor()
@@ -69,6 +73,7 @@ int PaletteModel::GetFgColor()
 void PaletteModel::SetFgColor(int newColor)
 {
     m_fgColor = newColor;
+    NotifyColorChanged();
 }
 
 int PaletteModel::GetBgColor()
@@ -79,4 +84,15 @@ int PaletteModel::GetBgColor()
 void PaletteModel::SetBgColor(int newColor)
 {
     m_bgColor = newColor;
+    NotifyColorChanged();
+}
+
+void PaletteModel::NotifyColorChanged()
+{
+    paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
+}
+
+void PaletteModel::NotifyPaletteChanged()
+{
+    paletteWindow.SendMessage(WM_PALETTEMODELPALETTECHANGED);
 }
index 232cab1..957ca57 100644 (file)
@@ -15,6 +15,10 @@ private:
     int m_nSelectedPalette;
     int m_fgColor;
     int m_bgColor;
+
+    void NotifyColorChanged();
+    void NotifyPaletteChanged();
+
 public:
     PaletteModel();
     int SelectedPalette();
index d14d8c6..123ee89 100644 (file)
@@ -32,6 +32,7 @@
 #include "selection.h"
 #include "sizebox.h"
 #include "textedit.h"
+#include "toolbox.h"
 #include "toolsettings.h"
 #include "toolsmodel.h"
 #include "winproc.h"
index 6fb3837..b187679 100644 (file)
@@ -11,7 +11,7 @@ class CScrollboxWindow : public CWindowImpl<CScrollboxWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("Scrollbox"), 0, COLOR_APPWORKSPACE)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CScrollboxWindow)
         MESSAGE_HANDLER(WM_SIZE, OnSize)
         MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
         MESSAGE_HANDLER(WM_VSCROLL, OnVScroll)
index 11280c5..916a20a 100644 (file)
@@ -11,7 +11,7 @@ class CSelectionWindow : public CWindowImpl<CSelectionWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("Selection"), CS_DBLCLKS, COLOR_BTNFACE)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CSelectionWindow)
         MESSAGE_HANDLER(WM_PAINT, OnPaint)
         MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
         MESSAGE_HANDLER(WM_CREATE, OnCreate)
index 7537875..d5511db 100644 (file)
@@ -11,7 +11,7 @@ class CSizeboxWindow : public CWindowImpl<CSizeboxWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("Sizebox"), CS_DBLCLKS, COLOR_HIGHLIGHT)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CSizeboxWindow)
         MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
         MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
index 7bd22a7..b65223b 100644 (file)
 #include "precomp.h"
 
 /* FUNCTIONS ********************************************************/
+LRESULT CTextEditWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    /* creating the edit control within the editor window */
+    RECT editControlPos = {0, 0, 0 + 100, 0 + 100};
+    hwndEditCtl = editControl.Create(_T("EDIT"), m_hWnd, editControlPos, NULL,
+                                     WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
+                                     WS_EX_CLIENTEDGE);
+    return 0;
+}
 
 LRESULT CTextEditWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     RECT clientRect;
     GetClientRect(&clientRect);
-    ::MoveWindow(hwndEditCtl, clientRect.left, clientRect.top, RECT_WIDTH(clientRect), RECT_HEIGHT(clientRect), TRUE);
+    editControl.MoveWindow(clientRect.left, clientRect.top, RECT_WIDTH(clientRect), RECT_HEIGHT(clientRect), TRUE);
     return 0;
 }
 
@@ -33,12 +42,18 @@ LRESULT CTextEditWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
         case EN_UPDATE:
         {
             HeapFree(GetProcessHeap(), 0, textToolText);
-            textToolTextMaxLen = ::GetWindowTextLength(hwndEditCtl) + 1;
+            textToolTextMaxLen = editControl.GetWindowTextLength() + 1;
             textToolText = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(TCHAR) * textToolTextMaxLen);
-            ::GetWindowText(hwndEditCtl, textToolText, textToolTextMaxLen);
+            editControl.GetWindowText(textToolText, textToolTextMaxLen);
             ForceRefreshSelectionContents();
             break;
         }
     }
     return 0;
 }
+
+LRESULT CTextEditWindow::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    ShowWindow((wParam == TOOL_TEXT) ? SW_SHOW : SW_HIDE);
+    return 0;
+}
index a8bc328..651236b 100644 (file)
@@ -11,13 +11,19 @@ class CTextEditWindow : public CWindowImpl<CTextEditWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("TextEdit"), CS_DBLCLKS, COLOR_BTNFACE)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CTextEditWindow)
+        MESSAGE_HANDLER(WM_CREATE, OnCreate)
         MESSAGE_HANDLER(WM_SIZE, OnSize)
         MESSAGE_HANDLER(WM_CLOSE, OnClose)
         MESSAGE_HANDLER(WM_COMMAND, OnCommand)
+        MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged)
     END_MSG_MAP()
 
+    CWindow editControl;
+
+    LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 };
diff --git a/reactos/base/applications/mspaint_new/toolbox.cpp b/reactos/base/applications/mspaint_new/toolbox.cpp
new file mode 100644 (file)
index 0000000..c85b7bd
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * PROJECT:     PAINT for ReactOS
+ * LICENSE:     LGPL
+ * FILE:        base/applications/mspaint_new/toolbox.cpp
+ * PURPOSE:     Window procedure of the main window and all children apart from
+ *              hPalWin, hToolSettings and hSelection
+ * PROGRAMMERS: Benedikt Freisen
+ */
+
+/* INCLUDES *********************************************************/
+
+#include "precomp.h"
+
+/* FUNCTIONS ********************************************************/
+
+LRESULT CToolBox::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    HIMAGELIST hImageList;
+    HBITMAP tempBm;
+    int i;
+    TCHAR tooltips[16][30];
+
+    /*
+     * FIXME: Unintentionally there is a line above the tool bar (hidden by y-offset).
+     * To prevent cropping of the buttons height has been increased from 200 to 205
+     */
+    RECT toolbarPos = {1, -2, 1 + 50, -2 + 205};
+    toolbar.Create(TOOLBARCLASSNAME, m_hWnd, toolbarPos, NULL,
+                   WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS);
+    hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
+    toolbar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM) hImageList);
+    tempBm = (HBITMAP) LoadImage((HINSTANCE) GetWindowLong(GWL_HINSTANCE), MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0);
+    ImageList_AddMasked(hImageList, tempBm, 0xff00ff);
+    DeleteObject(tempBm);
+    toolbar.SendMessage(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
+
+    for(i = 0; i < 16; i++)
+    {
+        TBBUTTON tbbutton;
+        int wrapnow = 0;
+
+        if (i % 2 == 1)
+            wrapnow = TBSTATE_WRAP;
+
+        LoadString((HINSTANCE) GetWindowLong(GWL_HINSTANCE), IDS_TOOLTIP1 + i, tooltips[i], 30);
+        ZeroMemory(&tbbutton, sizeof(TBBUTTON));
+        tbbutton.iString   = (INT_PTR) tooltips[i];
+        tbbutton.fsStyle   = TBSTYLE_CHECKGROUP;
+        tbbutton.fsState   = TBSTATE_ENABLED | wrapnow;
+        tbbutton.idCommand = ID_FREESEL + i;
+        tbbutton.iBitmap   = i;
+        toolbar.SendMessage(TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
+    }
+
+    toolbar.SendMessage(TB_CHECKBUTTON, ID_PEN, MAKELPARAM(TRUE, 0));
+    toolbar.SendMessage(TB_SETMAXTEXTROWS, 0, 0);
+    toolbar.SendMessage(TB_SETBUTTONSIZE, 0, MAKELPARAM(25, 25));
+
+    return 0;
+}
+
+LRESULT CToolBox::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    SetCursor(LoadCursor(NULL, IDC_ARROW));
+    return 0;
+}
+
+LRESULT CToolBox::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    toolbar.SendMessage(WM_SYSCOLORCHANGE, 0, 0);
+    return 0;
+}
+
+LRESULT CToolBox::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    switch (LOWORD(wParam))
+    {
+        case ID_FREESEL:
+            toolsModel.SetActiveTool(1);
+            break;
+        case ID_RECTSEL:
+            toolsModel.SetActiveTool(2);
+            break;
+        case ID_RUBBER:
+            toolsModel.SetActiveTool(3);
+            break;
+        case ID_FILL:
+            toolsModel.SetActiveTool(4);
+            break;
+        case ID_COLOR:
+            toolsModel.SetActiveTool(5);
+            break;
+        case ID_ZOOM:
+            toolsModel.SetActiveTool(6);
+            break;
+        case ID_PEN:
+            toolsModel.SetActiveTool(7);
+            break;
+        case ID_BRUSH:
+            toolsModel.SetActiveTool(8);
+            break;
+        case ID_AIRBRUSH:
+            toolsModel.SetActiveTool(9);
+            break;
+        case ID_TEXT:
+            toolsModel.SetActiveTool(10);
+            break;
+        case ID_LINE:
+            toolsModel.SetActiveTool(11);
+            break;
+        case ID_BEZIER:
+            toolsModel.SetActiveTool(12);
+            break;
+        case ID_RECT:
+            toolsModel.SetActiveTool(13);
+            break;
+        case ID_SHAPE:
+            toolsModel.SetActiveTool(14);
+            break;
+        case ID_ELLIPSE:
+            toolsModel.SetActiveTool(15);
+            break;
+        case ID_RRECT:
+            toolsModel.SetActiveTool(16);
+            break;
+    }
+    return 0;
+}
+
+LRESULT CToolBox::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    selectionWindow.ShowWindow(SW_HIDE);
+    pointSP = 0;                // resets the point-buffer of the polygon and bezier functions
+    return 0;
+}
diff --git a/reactos/base/applications/mspaint_new/toolbox.h b/reactos/base/applications/mspaint_new/toolbox.h
new file mode 100644 (file)
index 0000000..db7bbcc
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * PROJECT:     PAINT for ReactOS
+ * LICENSE:     LGPL
+ * FILE:        base/applications/mspaint_new/toolbox.h
+ * PURPOSE:     Window procedure of the main window and all children apart from
+ *              hPalWin, hToolSettings and hSelection
+ * PROGRAMMERS: Benedikt Freisen
+ */
+
+class CToolBox : public CWindowImpl<CMainWindow>
+{
+public:
+    DECLARE_WND_CLASS_EX(_T("ToolBox"), CS_DBLCLKS, COLOR_BTNFACE)
+
+    BEGIN_MSG_MAP(CToolBox)
+        MESSAGE_HANDLER(WM_CREATE, OnCreate)
+        MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
+        MESSAGE_HANDLER(WM_SYSCOLORCHANGE, OnSysColorChange)
+        MESSAGE_HANDLER(WM_COMMAND, OnCommand)
+        MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged)
+    END_MSG_MAP()
+
+    CWindow toolbar;
+
+    LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+};
index 576bc3e..7cd22af 100644 (file)
 
 extern void zoomTo(int, int, int);
 
+LRESULT CToolSettingsWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, WINBOOL& bHandled)
+{
+    RECT trackbarZoomPos = {1, 1, 1 + 40, 1 + 64};
+    trackbarZoom.Create(TRACKBAR_CLASS, m_hWnd, trackbarZoomPos, NULL, WS_CHILD | TBS_VERT | TBS_AUTOTICKS);
+    trackbarZoom.SendMessage(TBM_SETRANGE, (WPARAM) TRUE, MAKELPARAM(0, 6));
+    trackbarZoom.SendMessage(TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 3);
+    return 0;
+}
+
 LRESULT CToolSettingsWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    zoomTo(125 << SendMessage(hTrackbarZoom, TBM_GETPOS, 0, 0), 0, 0);
+    zoomTo(125 << trackbarZoom.SendMessage(TBM_GETPOS, 0, 0), 0, 0);
     return 0;
 }
 
@@ -181,25 +190,17 @@ LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lPar
             if ((y > 1) && (y < 64))
             {
                 toolsModel.SetBackgroundTransparent((y - 2) / 31);
-                InvalidateRect(NULL, TRUE);
 
                 ForceRefreshSelectionContents();
             }
             break;
         case TOOL_RUBBER:
             if ((y > 1) && (y < 62))
-            {
                 toolsModel.SetRubberRadius((y - 2) / 15 + 2);
-                InvalidateRect(NULL, TRUE);
-            }
             break;
         case TOOL_BRUSH:
-            if ((x > 1) && (x < 40) && (y > 1)
-                && (y < 62))
-            {
+            if ((x > 1) && (x < 40) && (y > 1) && (y < 62))
                 toolsModel.SetBrushStyle((y - 2) / 15 * 3 + (x - 2) / 13);
-                InvalidateRect(NULL, TRUE);
-            }
             break;
         case TOOL_AIRBRUSH:
             if (y < 62)
@@ -218,32 +219,49 @@ LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lPar
                     else
                         toolsModel.SetAirBrushWidth(12);
                 }
-                InvalidateRect(NULL, TRUE);
             }
             break;
         case TOOL_LINE:
         case TOOL_BEZIER:
             if (y <= 62)
-            {
                 toolsModel.SetLineWidth((y - 2) / 12 + 1);
-                InvalidateRect(NULL, TRUE);
-            }
             break;
         case TOOL_RECT:
         case TOOL_SHAPE:
         case TOOL_ELLIPSE:
         case TOOL_RRECT:
             if (y <= 60)
-            {
                 toolsModel.SetShapeStyle((y - 2) / 20);
-                InvalidateRect(NULL, TRUE);
-            }
             if ((y >= 70) && (y <= 132))
-            {
                 toolsModel.SetLineWidth((y - 72) / 12 + 1);
-                InvalidateRect(NULL, TRUE);
-            }
             break;
     }
     return 0;
 }
+
+LRESULT CToolSettingsWindow::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    Invalidate();
+    trackbarZoom.ShowWindow((wParam == TOOL_ZOOM) ? SW_SHOW : SW_HIDE);
+    return 0;
+}
+
+LRESULT CToolSettingsWindow::OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    Invalidate();
+    return 0;
+}
+
+LRESULT CToolSettingsWindow::OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    int tbPos = 0;
+    int tempZoom = toolsModel.GetZoom();
+
+    while (tempZoom > 125)
+    {
+        tbPos++;
+        tempZoom = tempZoom >> 1;
+    }
+    trackbarZoom.SendMessage(TBM_SETPOS, (WPARAM) TRUE, (LPARAM) tbPos);
+    return 0;
+}
index 63b8fec..224c5fd 100644 (file)
@@ -11,13 +11,23 @@ class CToolSettingsWindow : public CWindowImpl<CToolSettingsWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("ToolSettings"), CS_DBLCLKS, COLOR_BTNFACE)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CToolSettingsWindow)
+        MESSAGE_HANDLER(WM_CREATE, OnCreate)
         MESSAGE_HANDLER(WM_VSCROLL, OnVScroll)
         MESSAGE_HANDLER(WM_PAINT, OnPaint)
         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
+        MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged)
+        MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged)
+        MESSAGE_HANDLER(WM_TOOLSMODELZOOMCHANGED, OnToolsModelZoomChanged)
     END_MSG_MAP()
 
+    CWindow trackbarZoom;
+
+    LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+    LRESULT OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 };
index b87059e..05682a3 100644 (file)
@@ -32,6 +32,7 @@ int ToolsModel::GetLineWidth()
 void ToolsModel::SetLineWidth(int nLineWidth)
 {
     m_lineWidth = nLineWidth;
+    NotifyToolSettingsChanged();
 }
 
 int ToolsModel::GetShapeStyle()
@@ -42,6 +43,7 @@ int ToolsModel::GetShapeStyle()
 void ToolsModel::SetShapeStyle(int nShapeStyle)
 {
     m_shapeStyle = nShapeStyle;
+    NotifyToolSettingsChanged();
 }
 
 int ToolsModel::GetBrushStyle()
@@ -52,6 +54,7 @@ int ToolsModel::GetBrushStyle()
 void ToolsModel::SetBrushStyle(int nBrushStyle)
 {
     m_brushStyle = nBrushStyle;
+    NotifyToolSettingsChanged();
 }
 
 int ToolsModel::GetActiveTool()
@@ -62,6 +65,7 @@ int ToolsModel::GetActiveTool()
 void ToolsModel::SetActiveTool(int nActiveTool)
 {
     m_activeTool = nActiveTool;
+    NotifyToolChanged();
 }
 
 int ToolsModel::GetAirBrushWidth()
@@ -72,6 +76,7 @@ int ToolsModel::GetAirBrushWidth()
 void ToolsModel::SetAirBrushWidth(int nAirBrushWidth)
 {
     m_airBrushWidth = nAirBrushWidth;
+    NotifyToolSettingsChanged();
 }
 
 int ToolsModel::GetRubberRadius()
@@ -82,6 +87,7 @@ int ToolsModel::GetRubberRadius()
 void ToolsModel::SetRubberRadius(int nRubberRadius)
 {
     m_rubberRadius = nRubberRadius;
+    NotifyToolSettingsChanged();
 }
 
 BOOL ToolsModel::IsBackgroundTransparent()
@@ -92,6 +98,7 @@ BOOL ToolsModel::IsBackgroundTransparent()
 void ToolsModel::SetBackgroundTransparent(BOOL bTransparent)
 {
     m_transpBg = bTransparent;
+    NotifyToolSettingsChanged();
 }
 
 int ToolsModel::GetZoom()
@@ -102,4 +109,22 @@ int ToolsModel::GetZoom()
 void ToolsModel::SetZoom(int nZoom)
 {
     m_zoom = nZoom;
+    NotifyZoomChanged();
+}
+
+void ToolsModel::NotifyToolChanged()
+{
+    toolBoxContainer.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
+    toolSettingsWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
+    textEditWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
+}
+
+void ToolsModel::NotifyToolSettingsChanged()
+{
+    toolSettingsWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED);
+}
+
+void ToolsModel::NotifyZoomChanged()
+{
+    toolSettingsWindow.SendMessage(WM_TOOLSMODELZOOMCHANGED);
 }
index 4cbc74b..1275dee 100644 (file)
@@ -19,6 +19,11 @@ private:
     int m_rubberRadius;
     BOOL m_transpBg;
     int m_zoom;
+
+    void NotifyToolChanged();
+    void NotifyToolSettingsChanged();
+    void NotifyZoomChanged();
+
 public:
     ToolsModel();
     int GetLineWidth();
index 0cf0ff5..7c4cc82 100644 (file)
 
 /* FUNCTIONS ********************************************************/
 
-void CMainWindow::selectTool(int tool)
-{
-    selectionWindow.ShowWindow(SW_HIDE);
-    toolsModel.SetActiveTool(tool);
-    pointSP = 0;                // resets the point-buffer of the polygon and bezier functions
-    toolSettingsWindow.Invalidate(TRUE);
-    ::ShowWindow(hTrackbarZoom, (tool == TOOL_ZOOM) ? SW_SHOW : SW_HIDE);
-    textEditWindow.ShowWindow((tool == TOOL_TEXT) ? SW_SHOW : SW_HIDE);
-}
-
 void
 updateCanvasAndScrollbars()
 {
@@ -41,9 +31,6 @@ updateCanvasAndScrollbars()
 void
 zoomTo(int newZoom, int mouseX, int mouseY)
 {
-    int tbPos = 0;
-    int tempZoom = newZoom;
-
     RECT clientRectScrollbox;
     RECT clientRectImageArea;
     int x, y, w, h;
@@ -61,22 +48,15 @@ zoomTo(int newZoom, int mouseX, int mouseY)
     scrollboxWindow.Invalidate(TRUE);
     imageArea.Invalidate(FALSE);
 
-    scrollboxWindow.SendMessage(WM_HSCROLL, SB_THUMBPOSITION | (x << 16), 0);
-    scrollboxWindow.SendMessage(WM_VSCROLL, SB_THUMBPOSITION | (y << 16), 0);
-
-    while (tempZoom > 125)
-    {
-        tbPos++;
-        tempZoom = tempZoom >> 1;
-    }
-    SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) tbPos);
+    scrollboxWindow.SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, x), 0);
+    scrollboxWindow.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, y), 0);
 }
 
 void CMainWindow::alignChildrenToMainWindow()
 {
     int x, y, w, h;
     RECT clientRect;
-    mainWindow.GetClientRect(&clientRect);
+    GetClientRect(&clientRect);
 
     if (toolBoxContainer.IsWindowVisible())
     {
@@ -121,7 +101,7 @@ void CMainWindow::saveImage(BOOL overwrite)
         CopyMemory(filepathname, sfn.lpstrFile, sizeof(filepathname));
         LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
         _stprintf(tempstr, resstr, filename);
-        mainWindow.SetWindowText(tempstr);
+        SetWindowText(tempstr);
         isAFile = TRUE;
         imageSaved = TRUE;
     }
@@ -148,8 +128,8 @@ void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
     HBITMAP hTempMask;
 
     HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
-    SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
-    SendMessage(window, WM_COMMAND, ID_RECTSEL, 0);
+    SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
+    toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
 
     DeleteObject(SelectObject(hSelDC, hSelBm = (HBITMAP) CopyImage(bitmap,
                                                                    IMAGE_BITMAP, 0, 0,
@@ -290,25 +270,19 @@ LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM lParam, BO
 
 LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    if (m_hWnd == mainWindow.m_hWnd)
-    {
-        int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
-        SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
-        SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
-        alignChildrenToMainWindow();
-        Invalidate(TRUE);
-    }
+    int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
+    SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
+    SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
+    alignChildrenToMainWindow();
+    Invalidate(TRUE);
     return 0;
 }
 
 LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    if (m_hWnd == mainWindow.m_hWnd)
-    {
-        MINMAXINFO *mm = (LPMINMAXINFO) lParam;
-        mm->ptMinTrackSize.x = 330;
-        mm->ptMinTrackSize.y = 430;
-    }
+    MINMAXINFO *mm = (LPMINMAXINFO) lParam;
+    mm->ptMinTrackSize.x = 330;
+    mm->ptMinTrackSize.y = 430;
     return 0;
 }
 
@@ -357,12 +331,12 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
             TCHAR infotext[200];
             LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
             LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
-            ShellAbout(mainWindow.m_hWnd, infotitle, infotext, paintIcon);
+            ShellAbout(m_hWnd, infotitle, infotext, paintIcon);
             DeleteObject(paintIcon);
             break;
         }
         case IDM_HELPHELPTOPICS:
-            HtmlHelp(mainWindow.m_hWnd, _T("help\\Paint.chm"), 0, 0);
+            HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
             break;
         case IDM_FILEEXIT:
             SendMessage(WM_CLOSE, wParam, lParam);
@@ -475,8 +449,8 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
         case IDM_EDITSELECTALL:
         {
             HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
-            SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
-            SendMessage(WM_COMMAND, ID_RECTSEL, 0);
+            SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
+            toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
             startPaintingL(hDrawingDC, 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
             whilePaintingL(hDrawingDC, imgXRes, imgYRes, paletteModel.GetFgColor(), paletteModel.GetBgColor());
             endPaintingL(hDrawingDC, imgXRes, imgYRes, paletteModel.GetFgColor(), paletteModel.GetBgColor());
@@ -615,7 +589,6 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
         }
         case IDM_IMAGEDRAWOPAQUE:
             toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
-            toolSettingsWindow.Invalidate(TRUE);
             break;
         case IDM_IMAGECROP:
             insertReversible((HBITMAP) CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
@@ -667,54 +640,6 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
         case IDM_VIEWZOOM800:
             zoomTo(8000, 0, 0);
             break;
-        case ID_FREESEL:
-            selectTool(1);
-            break;
-        case ID_RECTSEL:
-            selectTool(2);
-            break;
-        case ID_RUBBER:
-            selectTool(3);
-            break;
-        case ID_FILL:
-            selectTool(4);
-            break;
-        case ID_COLOR:
-            selectTool(5);
-            break;
-        case ID_ZOOM:
-            selectTool(6);
-            break;
-        case ID_PEN:
-            selectTool(7);
-            break;
-        case ID_BRUSH:
-            selectTool(8);
-            break;
-        case ID_AIRBRUSH:
-            selectTool(9);
-            break;
-        case ID_TEXT:
-            selectTool(10);
-            break;
-        case ID_LINE:
-            selectTool(11);
-            break;
-        case ID_BEZIER:
-            selectTool(12);
-            break;
-        case ID_RECT:
-            selectTool(13);
-            break;
-        case ID_SHAPE:
-            selectTool(14);
-            break;
-        case ID_ELLIPSE:
-            selectTool(15);
-            break;
-        case ID_RRECT:
-            selectTool(16);
-            break;
     }
     return 0;
 }
index 1f400cf..5eaa2dc 100644 (file)
@@ -12,7 +12,7 @@ class CMainWindow : public CWindowImpl<CMainWindow>
 public:
     DECLARE_WND_CLASS_EX(_T("MainWindow"), CS_DBLCLKS, COLOR_BTNFACE)
 
-    BEGIN_MSG_MAP(CPaletteWindow)
+    BEGIN_MSG_MAP(CMainWindow)
         MESSAGE_HANDLER(WM_DROPFILES, OnDropFiles)
         MESSAGE_HANDLER(WM_CREATE, OnCreate)
         MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
@@ -38,7 +38,6 @@ public:
     LRESULT OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
     LRESULT OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    void selectTool(int tool);
     void alignChildrenToMainWindow();
     void saveImage(BOOL overwrite);
     void UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname);