2015-07-07 11:44:50 +00:00
|
|
|
/*
|
2023-06-23 11:04:32 +00:00
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
|
|
|
|
* PURPOSE: Window procedure of the main window and all children apart from
|
|
|
|
* hPalWin, hToolSettings and hSelection
|
2023-06-27 18:22:21 +00:00
|
|
|
* COPYRIGHT: Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
|
2015-07-07 11:44:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2023-03-28 13:31:26 +00:00
|
|
|
CToolBox toolBoxContainer;
|
|
|
|
|
2015-07-07 11:44:50 +00:00
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
2023-06-17 12:15:35 +00:00
|
|
|
LRESULT CALLBACK
|
|
|
|
CPaintToolBar::ToolBarWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
WNDPROC oldWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
if (uMsg == WM_LBUTTONUP)
|
|
|
|
{
|
|
|
|
// We have to detect clicking on toolbar even if no change of pressed button
|
|
|
|
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
2023-11-04 10:25:45 +00:00
|
|
|
INT index = (INT)::SendMessageW(hwnd, TB_HITTEST, 0, (LPARAM)&pt);
|
2023-09-28 07:32:36 +00:00
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
TBBUTTON button;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (::SendMessageW(hwnd, TB_GETBUTTON, index, (LPARAM)&button))
|
|
|
|
::PostMessageW(::GetParent(hwnd), WM_COMMAND, button.idCommand, 0);
|
2023-09-28 07:32:36 +00:00
|
|
|
}
|
2023-06-17 12:15:35 +00:00
|
|
|
}
|
|
|
|
return ::CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
BOOL CPaintToolBar::DoCreate(HWND hwndParent)
|
2015-07-07 11:44:50 +00:00
|
|
|
{
|
2023-04-03 05:34:56 +00:00
|
|
|
// NOTE: The horizontal line above the toolbar is hidden by CCS_NODIVIDER style.
|
2023-10-08 23:37:31 +00:00
|
|
|
RECT toolbarPos =
|
|
|
|
{
|
|
|
|
0, 0,
|
|
|
|
CX_TOOLBAR + 2 * GetSystemMetrics(SM_CXBORDER),
|
|
|
|
CY_TOOLBAR + 2 * GetSystemMetrics(SM_CYBORDER)
|
|
|
|
};
|
2023-03-14 22:29:25 +00:00
|
|
|
DWORD style = WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE |
|
2023-03-17 10:18:07 +00:00
|
|
|
TBSTYLE_TOOLTIPS | TBSTYLE_FLAT;
|
2023-11-04 10:25:45 +00:00
|
|
|
if (!CWindow::Create(TOOLBARCLASSNAMEW, hwndParent, toolbarPos, NULL, style))
|
2023-04-03 05:34:56 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
|
|
|
|
SendMessage(TB_SETIMAGELIST, 0, (LPARAM)hImageList);
|
2015-07-07 11:44:50 +00:00
|
|
|
|
2023-11-04 10:25:45 +00:00
|
|
|
HBITMAP hbmIcons = (HBITMAP)::LoadImageW(g_hinstExe, MAKEINTRESOURCEW(IDB_TOOLBARICONS),
|
|
|
|
IMAGE_BITMAP, 256, 16, 0);
|
2023-04-03 05:34:56 +00:00
|
|
|
ImageList_AddMasked(hImageList, hbmIcons, RGB(255, 0, 255));
|
|
|
|
::DeleteObject(hbmIcons);
|
2015-07-07 11:44:50 +00:00
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
SendMessage(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
|
|
|
|
|
2023-11-04 10:25:45 +00:00
|
|
|
WCHAR szToolTip[30];
|
2023-04-03 05:34:56 +00:00
|
|
|
TBBUTTON tbbutton;
|
|
|
|
ZeroMemory(&tbbutton, sizeof(tbbutton));
|
|
|
|
tbbutton.fsStyle = TBSTYLE_CHECKGROUP;
|
|
|
|
for (INT i = 0; i < NUM_TOOLS; i++)
|
|
|
|
{
|
2023-11-04 10:25:45 +00:00
|
|
|
::LoadStringW(g_hinstExe, IDS_TOOLTIP1 + i, szToolTip, _countof(szToolTip));
|
2023-04-03 05:34:56 +00:00
|
|
|
tbbutton.iString = (INT_PTR)szToolTip;
|
|
|
|
tbbutton.fsState = TBSTATE_ENABLED | ((i % 2 == 1) ? TBSTATE_WRAP : 0);
|
2015-07-07 11:44:50 +00:00
|
|
|
tbbutton.idCommand = ID_FREESEL + i;
|
|
|
|
tbbutton.iBitmap = i;
|
2023-04-03 05:34:56 +00:00
|
|
|
SendMessage(TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
|
2015-07-07 11:44:50 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
SendMessage(TB_CHECKBUTTON, ID_PEN, MAKELPARAM(TRUE, 0));
|
|
|
|
SendMessage(TB_SETMAXTEXTROWS, 0, 0);
|
|
|
|
SendMessage(TB_SETBUTTONSIZE, 0, MAKELPARAM(CXY_TB_BUTTON, CXY_TB_BUTTON));
|
2023-06-17 12:15:35 +00:00
|
|
|
|
|
|
|
SetWindowLongPtr(GWLP_USERDATA, SetWindowLongPtr(GWLP_WNDPROC, (LONG_PTR)ToolBarWndProc));
|
2023-04-03 05:34:56 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CToolBox::DoCreate(HWND hwndParent)
|
|
|
|
{
|
|
|
|
RECT rcToolBox = { 0, 0, 0, 0 }; // Rely on mainWindow's WM_SIZE
|
|
|
|
DWORD style = WS_CHILD | (registrySettings.ShowToolBox ? WS_VISIBLE : 0);
|
|
|
|
return !!Create(hwndParent, rcToolBox, NULL, style);
|
|
|
|
}
|
2015-07-07 11:44:50 +00:00
|
|
|
|
2023-04-03 05:34:56 +00:00
|
|
|
LRESULT CToolBox::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
toolbar.DoCreate(m_hWnd);
|
|
|
|
toolSettingsWindow.DoCreate(m_hWnd);
|
2015-07-07 11:44:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CToolBox::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
toolbar.SendMessage(WM_SYSCOLORCHANGE, 0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-01 13:02:36 +00:00
|
|
|
struct COMMAND_TO_TOOL
|
|
|
|
{
|
|
|
|
UINT id;
|
|
|
|
TOOLTYPE tool;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const COMMAND_TO_TOOL CommandToToolMapping[] =
|
|
|
|
{
|
|
|
|
{ ID_FREESEL, TOOL_FREESEL },
|
|
|
|
{ ID_RECTSEL, TOOL_RECTSEL },
|
|
|
|
{ ID_RUBBER, TOOL_RUBBER },
|
|
|
|
{ ID_FILL, TOOL_FILL },
|
|
|
|
{ ID_COLOR, TOOL_COLOR },
|
|
|
|
{ ID_ZOOM, TOOL_ZOOM },
|
|
|
|
{ ID_PEN, TOOL_PEN },
|
|
|
|
{ ID_BRUSH, TOOL_BRUSH },
|
|
|
|
{ ID_AIRBRUSH, TOOL_AIRBRUSH },
|
|
|
|
{ ID_TEXT, TOOL_TEXT },
|
|
|
|
{ ID_LINE, TOOL_LINE },
|
|
|
|
{ ID_BEZIER, TOOL_BEZIER },
|
|
|
|
{ ID_RECT, TOOL_RECT },
|
|
|
|
{ ID_SHAPE, TOOL_SHAPE },
|
|
|
|
{ ID_ELLIPSE, TOOL_ELLIPSE },
|
|
|
|
{ ID_RRECT, TOOL_RRECT },
|
|
|
|
};
|
2023-09-28 07:32:36 +00:00
|
|
|
static_assert(_countof(CommandToToolMapping) == TOOL_MAX, "Logical error");
|
2022-01-01 13:02:36 +00:00
|
|
|
|
2015-07-07 11:44:50 +00:00
|
|
|
LRESULT CToolBox::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2022-01-01 13:02:36 +00:00
|
|
|
UINT id = LOWORD(wParam);
|
|
|
|
for (size_t i = 0; i < _countof(CommandToToolMapping); ++i)
|
2015-07-07 11:44:50 +00:00
|
|
|
{
|
2022-01-01 13:02:36 +00:00
|
|
|
if (CommandToToolMapping[i].id == id)
|
|
|
|
{
|
|
|
|
toolsModel.SetActiveTool(CommandToToolMapping[i].tool);
|
2015-07-07 11:44:50 +00:00
|
|
|
break;
|
2022-01-01 13:02:36 +00:00
|
|
|
}
|
2015-07-07 11:44:50 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CToolBox::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
2023-06-17 12:15:35 +00:00
|
|
|
selectionModel.HideSelection();
|
2022-01-01 13:02:36 +00:00
|
|
|
toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
|
|
|
|
|
|
|
|
// Check the toolbar button
|
|
|
|
TOOLTYPE tool = toolsModel.GetActiveTool();
|
|
|
|
for (size_t i = 0; i < _countof(CommandToToolMapping); ++i)
|
|
|
|
{
|
|
|
|
if (CommandToToolMapping[i].tool == tool)
|
|
|
|
{
|
|
|
|
toolbar.SendMessage(TB_CHECKBUTTON, CommandToToolMapping[i].id, TRUE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:44:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2023-04-03 05:34:56 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-04-04 10:06:06 +00:00
|
|
|
POINT ptCenter = { (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2 };
|
2023-04-03 05:34:56 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|