mirror of
https://github.com/reactos/reactos.git
synced 2024-10-31 20:02:55 +00:00
[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
This commit is contained in:
parent
ce562727b8
commit
83e83bfd2c
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<CToolBox>
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
|
|
@ -414,6 +414,8 @@ LRESULT CToolSettingsWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lPar
|
|||
case TOOL_PEN:
|
||||
break;
|
||||
}
|
||||
|
||||
::SetCapture(::GetParent(m_hWnd));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,16 @@ void CMainWindow::alignChildrenToMainWindow()
|
|||
HDWP hDWP = ::BeginDeferWindowPos(3);
|
||||
|
||||
if (::IsWindowVisible(toolBoxContainer))
|
||||
{
|
||||
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,
|
||||
|
@ -94,6 +104,7 @@ void CMainWindow::alignChildrenToMainWindow()
|
|||
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION);
|
||||
rcSpace.left += CX_TOOLBAR;
|
||||
}
|
||||
}
|
||||
|
||||
if (::IsWindowVisible(paletteWindow))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue