From 83e83bfd2c3a4e6e54a3f894d81eb86f0eb0a720 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Mon, 3 Apr 2023 14:34:56 +0900 Subject: [PATCH] [MSPAINT] Allow ToolBox to be right-aligned (#5213) The user will be able to move ToolBox in the main window by dragging. - Add Bar2ID registry setting. - Add CPaintToolBar class to encapsulate the toolbar code. - Capture and track the mouse dragging in CToolBox. - Move the ToolBox if dragging is beyond the center position. CORE-18867 --- base/applications/mspaint/registry.cpp | 13 +++ base/applications/mspaint/registry.h | 6 + base/applications/mspaint/toolbox.cpp | 122 ++++++++++++++------- base/applications/mspaint/toolbox.h | 14 ++- base/applications/mspaint/toolsettings.cpp | 2 + base/applications/mspaint/winproc.cpp | 21 +++- 6 files changed, 130 insertions(+), 48 deletions(-) diff --git a/base/applications/mspaint/registry.cpp b/base/applications/mspaint/registry.cpp index fbf659fb70c..5a2b15121e3 100644 --- a/base/applications/mspaint/registry.cpp +++ b/base/applications/mspaint/registry.cpp @@ -75,6 +75,7 @@ void RegistrySettings::LoadPresets(INT nCmdShow) ShowStatusBar = TRUE; ShowPalette = TRUE; ShowToolBox = TRUE; + Bar2ID = BAR2ID_LEFT; LOGFONT lf; GetObject(GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf); @@ -141,6 +142,12 @@ void RegistrySettings::Load(INT nCmdShow) ReadString(text, _T("TypeFaceName"), strFontName, strFontName); } + CRegKey bar2; + if (bar2.Open(paint, _T("General-Bar2"), KEY_READ) == ERROR_SUCCESS) + { + ReadDWORD(bar2, _T("BarID"), Bar2ID); + } + CRegKey bar3; if (bar3.Open(paint, _T("General-Bar3"), KEY_READ) == ERROR_SUCCESS) { @@ -213,6 +220,12 @@ void RegistrySettings::Store() text.SetStringValue(_T("TypeFaceName"), strFontName); } + CRegKey bar2; + if (bar2.Create(paint, _T("General-Bar2")) == ERROR_SUCCESS) + { + bar2.SetDWORDValue(_T("BarID"), Bar2ID); + } + CRegKey bar3; if (bar3.Create(paint, _T("General-Bar3")) == ERROR_SUCCESS) { diff --git a/base/applications/mspaint/registry.h b/base/applications/mspaint/registry.h index d70e82ede48..7749328cd10 100644 --- a/base/applications/mspaint/registry.h +++ b/base/applications/mspaint/registry.h @@ -43,6 +43,12 @@ public: DWORD ShowStatusBar; DWORD ShowPalette; DWORD ShowToolBox; + DWORD Bar2ID; + +// Values for Bar2ID. +// I think these values are Win2k3 mspaint compatible but sometimes not working... +#define BAR2ID_LEFT 0x0000e81c +#define BAR2ID_RIGHT 0x0000e81d enum WallpaperStyle { TILED, diff --git a/base/applications/mspaint/toolbox.cpp b/base/applications/mspaint/toolbox.cpp index 64f90f9c807..c7a4667ac87 100644 --- a/base/applications/mspaint/toolbox.cpp +++ b/base/applications/mspaint/toolbox.cpp @@ -13,56 +13,56 @@ CToolBox toolBoxContainer; /* FUNCTIONS ********************************************************/ +BOOL CPaintToolBar::DoCreate(HWND hwndParent) +{ + // NOTE: The horizontal line above the toolbar is hidden by CCS_NODIVIDER style. + RECT toolbarPos = { 0, 0, CX_TOOLBAR, CY_TOOLBAR }; + DWORD style = WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | + TBSTYLE_TOOLTIPS | TBSTYLE_FLAT; + if (!CWindow::Create(TOOLBARCLASSNAME, hwndParent, toolbarPos, NULL, style)) + return FALSE; + + HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0); + SendMessage(TB_SETIMAGELIST, 0, (LPARAM)hImageList); + + HBITMAP hbmIcons = (HBITMAP)::LoadImage(hProgInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), + IMAGE_BITMAP, 256, 16, 0); + ImageList_AddMasked(hImageList, hbmIcons, RGB(255, 0, 255)); + ::DeleteObject(hbmIcons); + + SendMessage(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); + + TCHAR szToolTip[30]; + TBBUTTON tbbutton; + ZeroMemory(&tbbutton, sizeof(tbbutton)); + tbbutton.fsStyle = TBSTYLE_CHECKGROUP; + for (INT i = 0; i < NUM_TOOLS; i++) + { + ::LoadString(hProgInstance, IDS_TOOLTIP1 + i, szToolTip, _countof(szToolTip)); + tbbutton.iString = (INT_PTR)szToolTip; + tbbutton.fsState = TBSTATE_ENABLED | ((i % 2 == 1) ? TBSTATE_WRAP : 0); + tbbutton.idCommand = ID_FREESEL + i; + tbbutton.iBitmap = i; + SendMessage(TB_ADDBUTTONS, 1, (LPARAM) &tbbutton); + } + + SendMessage(TB_CHECKBUTTON, ID_PEN, MAKELPARAM(TRUE, 0)); + SendMessage(TB_SETMAXTEXTROWS, 0, 0); + SendMessage(TB_SETBUTTONSIZE, 0, MAKELPARAM(CXY_TB_BUTTON, CXY_TB_BUTTON)); + return TRUE; +} + BOOL CToolBox::DoCreate(HWND hwndParent) { - RECT toolBoxContainerPos = { 0, 0, 0, 0 }; + RECT rcToolBox = { 0, 0, 0, 0 }; // Rely on mainWindow's WM_SIZE DWORD style = WS_CHILD | (registrySettings.ShowToolBox ? WS_VISIBLE : 0); - return !!Create(hwndParent, toolBoxContainerPos, NULL, style); + return !!Create(hwndParent, rcToolBox, NULL, style); } LRESULT CToolBox::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - HIMAGELIST hImageList; - HBITMAP tempBm; - int i; - TCHAR tooltips[NUM_TOOLS][30]; - + toolbar.DoCreate(m_hWnd); toolSettingsWindow.DoCreate(m_hWnd); - - /* NOTE: The horizontal line above the toolbar is hidden by CCS_NODIVIDER style. */ - RECT toolbarPos = {0, 0, CX_TOOLBAR, CY_TOOLBAR}; - DWORD style = WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | - TBSTYLE_TOOLTIPS | TBSTYLE_FLAT; - toolbar.Create(TOOLBARCLASSNAME, m_hWnd, toolbarPos, NULL, style); - hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0); - toolbar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM) hImageList); - tempBm = (HBITMAP) LoadImage(hProgInstance, 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 < NUM_TOOLS; i++) - { - TBBUTTON tbbutton; - int wrapnow = 0; - - if (i % 2 == 1) - wrapnow = TBSTATE_WRAP; - - LoadString(hProgInstance, 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(CXY_TB_BUTTON, CXY_TB_BUTTON)); - return 0; } @@ -130,3 +130,41 @@ LRESULT CToolBox::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lPara return 0; } + +LRESULT CToolBox::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + SetCapture(); + return 0; +} + +LRESULT CToolBox::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if (::GetCapture() != m_hWnd) + return 0; + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + ClientToScreen(&pt); + + RECT rc; + mainWindow.GetWindowRect(&rc); + + POINT ptCenter = { (rc.left + rc.right) / 2, (rc.bottom - rc.top) / 2 }; + + DWORD dwExpectedBar2ID = ((pt.x < ptCenter.x) ? BAR2ID_LEFT : BAR2ID_RIGHT); + + if (registrySettings.Bar2ID != dwExpectedBar2ID) + { + registrySettings.Bar2ID = dwExpectedBar2ID; + mainWindow.PostMessage(WM_SIZE, 0, 0); + } + + return 0; +} + +LRESULT CToolBox::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if (::GetCapture() != m_hWnd) + return 0; + + ::ReleaseCapture(); + return 0; +} diff --git a/base/applications/mspaint/toolbox.h b/base/applications/mspaint/toolbox.h index b6699c67455..bd0a635636a 100644 --- a/base/applications/mspaint/toolbox.h +++ b/base/applications/mspaint/toolbox.h @@ -15,6 +15,12 @@ #define CX_TOOLBAR (TOOLBAR_COLUMNS * CXY_TB_BUTTON) #define CY_TOOLBAR (TOOLBAR_ROWS * CXY_TB_BUTTON) +class CPaintToolBar : public CWindow +{ +public: + BOOL DoCreate(HWND hwndParent); +}; + class CToolBox : public CWindowImpl { public: @@ -24,16 +30,22 @@ public: MESSAGE_HANDLER(WM_CREATE, OnCreate) MESSAGE_HANDLER(WM_SYSCOLORCHANGE, OnSysColorChange) MESSAGE_HANDLER(WM_COMMAND, OnCommand) + MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown) + MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove) + MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp) MESSAGE_HANDLER(WM_TOOLSMODELTOOLCHANGED, OnToolsModelToolChanged) END_MSG_MAP() BOOL DoCreate(HWND hwndParent); private: - CWindow toolbar; + CPaintToolBar toolbar; LRESULT OnCreate(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 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 OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); }; diff --git a/base/applications/mspaint/toolsettings.cpp b/base/applications/mspaint/toolsettings.cpp index d70a3dd7f5e..6ff0aed291d 100644 --- a/base/applications/mspaint/toolsettings.cpp +++ b/base/applications/mspaint/toolsettings.cpp @@ -414,6 +414,8 @@ LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lPar case TOOL_PEN: break; } + + ::SetCapture(::GetParent(m_hWnd)); return 0; } diff --git a/base/applications/mspaint/winproc.cpp b/base/applications/mspaint/winproc.cpp index b44534a8043..66e29e742b3 100644 --- a/base/applications/mspaint/winproc.cpp +++ b/base/applications/mspaint/winproc.cpp @@ -88,11 +88,22 @@ void CMainWindow::alignChildrenToMainWindow() if (::IsWindowVisible(toolBoxContainer)) { - hDWP = ::DeferWindowPos(hDWP, toolBoxContainer, NULL, - rcSpace.left, rcSpace.top, - CX_TOOLBAR, rcSpace.bottom - rcSpace.top, - SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION); - rcSpace.left += CX_TOOLBAR; + if (registrySettings.Bar2ID == BAR2ID_RIGHT) + { + hDWP = ::DeferWindowPos(hDWP, toolBoxContainer, NULL, + rcSpace.right - CX_TOOLBAR, rcSpace.top, + CX_TOOLBAR, rcSpace.bottom - rcSpace.top, + SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION); + rcSpace.right -= CX_TOOLBAR; + } + else + { + hDWP = ::DeferWindowPos(hDWP, toolBoxContainer, NULL, + rcSpace.left, rcSpace.top, + CX_TOOLBAR, rcSpace.bottom - rcSpace.top, + SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION); + rcSpace.left += CX_TOOLBAR; + } } if (::IsWindowVisible(paletteWindow))