2015-05-08 16:02:36 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: PAINT for ReactOS
|
|
|
|
* LICENSE: LGPL
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/mspaint/scrollbox.cpp
|
2015-05-08 16:02:36 +00:00
|
|
|
* PURPOSE: Functionality surrounding the scroll box window class
|
|
|
|
* PROGRAMMERS: Benedikt Freisen
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *********************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
2018-11-16 22:05:51 +00:00
|
|
|
#include <atltypes.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scrollbar functional modes:
|
|
|
|
* 0 view < canvas
|
|
|
|
* 1 view < canvas + scroll width
|
|
|
|
* 2 view >= canvas + scroll width
|
|
|
|
*
|
|
|
|
* Matrix of scrollbar presence (VERTICAL,HORIZONTAL) given by
|
|
|
|
* vertical & horizontal scrollbar modes (view:canvas ratio):
|
|
|
|
*
|
|
|
|
* horizontal mode
|
|
|
|
* | 0 | 1 | 2
|
|
|
|
* vertical ---+-------------+-------------+------------
|
|
|
|
* mode 0 | TRUE,TRUE | TRUE,TRUE | TRUE,FALSE
|
|
|
|
* ---+-------------+-------------+------------
|
|
|
|
* 1 | TRUE,TRUE | FALSE,FALSE | FALSE,FALSE
|
|
|
|
* ---+-------------+-------------+------------
|
|
|
|
* 2 | FALSE,TRUE | FALSE,FALSE | FALSE,FALSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ScrollbarPresence
|
|
|
|
{
|
|
|
|
BOOL bVert;
|
|
|
|
BOOL bHoriz;
|
|
|
|
};
|
|
|
|
|
|
|
|
CONST ScrollbarPresence sp_mx[3][3] =
|
|
|
|
{
|
|
|
|
{ { TRUE,TRUE }, { TRUE,TRUE }, { TRUE,FALSE } },
|
|
|
|
{ { TRUE,TRUE }, { FALSE,FALSE }, { FALSE,FALSE } },
|
|
|
|
{ { FALSE,TRUE }, { FALSE,FALSE }, { FALSE,FALSE } }
|
|
|
|
};
|
|
|
|
|
|
|
|
CONST INT HSCROLL_WIDTH = ::GetSystemMetrics(SM_CYHSCROLL);
|
|
|
|
CONST INT VSCROLL_WIDTH = ::GetSystemMetrics(SM_CXVSCROLL);
|
|
|
|
|
2015-05-08 16:02:36 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ********************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateScrollbox()
|
|
|
|
{
|
2018-11-16 22:05:51 +00:00
|
|
|
CRect tempRect;
|
|
|
|
CSize sizeImageArea;
|
|
|
|
CSize sizeScrollBox;
|
|
|
|
INT vmode, hmode;
|
2015-05-08 16:02:36 +00:00
|
|
|
SCROLLINFO si;
|
2018-11-16 22:05:51 +00:00
|
|
|
|
|
|
|
scrollboxWindow.GetWindowRect(&tempRect);
|
|
|
|
sizeScrollBox = CSize(tempRect.Width(), tempRect.Height());
|
|
|
|
|
2022-01-22 15:59:12 +00:00
|
|
|
if (imageArea.IsWindow())
|
|
|
|
imageArea.GetClientRect(&tempRect);
|
2018-11-16 22:05:51 +00:00
|
|
|
sizeImageArea = CSize(tempRect.Width(), tempRect.Height());
|
2021-12-26 14:05:47 +00:00
|
|
|
sizeImageArea += CSize(GRIP_SIZE * 2, GRIP_SIZE * 2);
|
2018-11-16 22:05:51 +00:00
|
|
|
|
|
|
|
/* show/hide the scrollbars */
|
|
|
|
vmode = (sizeScrollBox.cy < sizeImageArea.cy ? 0 :
|
|
|
|
(sizeScrollBox.cy < sizeImageArea.cy + HSCROLL_WIDTH ? 1 : 2));
|
|
|
|
hmode = (sizeScrollBox.cx < sizeImageArea.cx ? 0 :
|
|
|
|
(sizeScrollBox.cx < sizeImageArea.cx + VSCROLL_WIDTH ? 1 : 2));
|
|
|
|
scrollboxWindow.ShowScrollBar(SB_VERT, sp_mx[vmode][hmode].bVert);
|
|
|
|
scrollboxWindow.ShowScrollBar(SB_HORZ, sp_mx[vmode][hmode].bHoriz);
|
|
|
|
|
2015-05-08 16:02:36 +00:00
|
|
|
si.cbSize = sizeof(SCROLLINFO);
|
|
|
|
si.fMask = SIF_PAGE | SIF_RANGE;
|
|
|
|
si.nMin = 0;
|
2018-11-16 22:05:51 +00:00
|
|
|
|
|
|
|
si.nMax = sizeImageArea.cx +
|
|
|
|
(sp_mx[vmode][hmode].bVert == TRUE ? HSCROLL_WIDTH : 0);
|
|
|
|
si.nPage = sizeScrollBox.cx;
|
2015-07-07 10:42:49 +00:00
|
|
|
scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
|
2018-11-16 22:05:51 +00:00
|
|
|
|
|
|
|
si.nMax = sizeImageArea.cy +
|
|
|
|
(sp_mx[vmode][hmode].bHoriz == TRUE ? VSCROLL_WIDTH : 0);
|
|
|
|
si.nPage = sizeScrollBox.cy;
|
2015-07-07 10:42:49 +00:00
|
|
|
scrollboxWindow.SetScrollInfo(SB_VERT, &si);
|
2018-11-16 22:05:51 +00:00
|
|
|
|
2022-01-22 15:59:12 +00:00
|
|
|
if (scrlClientWindow.IsWindow())
|
|
|
|
{
|
|
|
|
scrlClientWindow.MoveWindow(
|
|
|
|
-scrollboxWindow.GetScrollPos(SB_HORZ), -scrollboxWindow.GetScrollPos(SB_VERT),
|
|
|
|
sizeImageArea.cx, sizeImageArea.cy, TRUE);
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CScrollboxWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2022-01-22 15:59:12 +00:00
|
|
|
if (m_hWnd && m_hWnd == scrollboxWindow.m_hWnd)
|
2015-05-08 16:02:36 +00:00
|
|
|
{
|
2015-07-07 10:42:49 +00:00
|
|
|
UpdateScrollbox();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CScrollboxWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (m_hWnd == scrollboxWindow.m_hWnd)
|
|
|
|
{
|
|
|
|
SCROLLINFO si;
|
|
|
|
si.cbSize = sizeof(SCROLLINFO);
|
|
|
|
si.fMask = SIF_ALL;
|
|
|
|
scrollboxWindow.GetScrollInfo(SB_HORZ, &si);
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case SB_THUMBTRACK:
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
si.nPos = HIWORD(wParam);
|
|
|
|
break;
|
|
|
|
case SB_LINELEFT:
|
|
|
|
si.nPos -= 5;
|
|
|
|
break;
|
|
|
|
case SB_LINERIGHT:
|
|
|
|
si.nPos += 5;
|
|
|
|
break;
|
|
|
|
case SB_PAGELEFT:
|
|
|
|
si.nPos -= si.nPage;
|
|
|
|
break;
|
|
|
|
case SB_PAGERIGHT:
|
|
|
|
si.nPos += si.nPage;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
scrollboxWindow.SetScrollInfo(SB_HORZ, &si);
|
|
|
|
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
|
2021-12-26 14:05:47 +00:00
|
|
|
-scrollboxWindow.GetScrollPos(SB_VERT),
|
|
|
|
Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE,
|
|
|
|
Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE);
|
2015-05-08 16:02:36 +00:00
|
|
|
}
|
2015-07-07 10:42:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
|
2015-07-07 10:42:49 +00:00
|
|
|
LRESULT CScrollboxWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (m_hWnd == scrollboxWindow.m_hWnd)
|
|
|
|
{
|
|
|
|
SCROLLINFO si;
|
|
|
|
si.cbSize = sizeof(SCROLLINFO);
|
|
|
|
si.fMask = SIF_ALL;
|
|
|
|
scrollboxWindow.GetScrollInfo(SB_VERT, &si);
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case SB_THUMBTRACK:
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
si.nPos = HIWORD(wParam);
|
|
|
|
break;
|
|
|
|
case SB_LINEUP:
|
|
|
|
si.nPos -= 5;
|
|
|
|
break;
|
|
|
|
case SB_LINEDOWN:
|
|
|
|
si.nPos += 5;
|
|
|
|
break;
|
|
|
|
case SB_PAGEUP:
|
|
|
|
si.nPos -= si.nPage;
|
|
|
|
break;
|
|
|
|
case SB_PAGEDOWN:
|
|
|
|
si.nPos += si.nPage;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
scrollboxWindow.SetScrollInfo(SB_VERT, &si);
|
|
|
|
scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
|
2021-12-26 14:05:47 +00:00
|
|
|
-scrollboxWindow.GetScrollPos(SB_VERT),
|
|
|
|
Zoomed(imageModel.GetWidth()) + 2 * GRIP_SIZE,
|
|
|
|
Zoomed(imageModel.GetHeight()) + 2 * GRIP_SIZE, TRUE);
|
2015-07-07 10:42:49 +00:00
|
|
|
}
|
2015-05-08 16:02:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-06-19 13:02:09 +00:00
|
|
|
|
|
|
|
LRESULT CScrollboxWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
selectionWindow.ShowWindow(SW_HIDE);
|
2022-01-01 13:02:36 +00:00
|
|
|
|
|
|
|
switch (toolsModel.GetActiveTool())
|
|
|
|
{
|
|
|
|
case TOOL_BEZIER:
|
|
|
|
case TOOL_SHAPE:
|
|
|
|
if (ToolBase::pointSP != 0)
|
|
|
|
{
|
|
|
|
toolsModel.OnCancelDraw();
|
|
|
|
imageArea.Invalidate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
toolsModel.resetTool(); // resets the point-buffer of the polygon and bezier functions
|
2017-06-19 13:02:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-27 13:20:22 +00:00
|
|
|
|
|
|
|
LRESULT CScrollboxWindow::OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
return ::SendMessage(GetParent(), nMsg, wParam, lParam);
|
|
|
|
}
|