comctl32/pager: Don't rely on PGN_CALCSIZE to set the non-scrollable dimension of the control.

This commit is contained in:
Alexandre Julliard 2012-11-20 17:18:17 +01:00
parent 7a78eed463
commit 3ad9f29e02

View file

@ -205,22 +205,24 @@ PAGER_GetBkColor(const PAGER_INFO *infoPtr)
}
static void
PAGER_CalcSize (const PAGER_INFO *infoPtr, INT* size, BOOL getWidth)
PAGER_CalcSize( PAGER_INFO *infoPtr )
{
NMPGCALCSIZE nmpgcs;
ZeroMemory (&nmpgcs, sizeof (NMPGCALCSIZE));
nmpgcs.hdr.hwndFrom = infoPtr->hwndSelf;
nmpgcs.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
nmpgcs.hdr.code = PGN_CALCSIZE;
nmpgcs.dwFlag = getWidth ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
nmpgcs.iWidth = getWidth ? *size : 0;
nmpgcs.iHeight = getWidth ? 0 : *size;
nmpgcs.dwFlag = (infoPtr->dwStyle & PGS_HORZ) ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
nmpgcs.iWidth = infoPtr->nWidth;
nmpgcs.iHeight = infoPtr->nHeight;
SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmpgcs.hdr.idFrom, (LPARAM)&nmpgcs);
*size = getWidth ? nmpgcs.iWidth : nmpgcs.iHeight;
if (infoPtr->dwStyle & PGS_HORZ)
infoPtr->nWidth = nmpgcs.iWidth;
else
infoPtr->nHeight = nmpgcs.iHeight;
TRACE("[%p] PGN_CALCSIZE returns %s=%d\n", infoPtr->hwndSelf,
getWidth ? "width" : "height", *size);
TRACE("[%p] PGN_CALCSIZE returns %dx%d\n", infoPtr->hwndSelf, nmpgcs.iWidth, nmpgcs.iHeight );
}
static void
@ -281,16 +283,15 @@ PAGER_GetScrollRange(PAGER_INFO* infoPtr)
RECT wndRect;
GetWindowRect(infoPtr->hwndSelf, &wndRect);
PAGER_CalcSize(infoPtr);
if (infoPtr->dwStyle & PGS_HORZ)
{
wndSize = wndRect.right - wndRect.left;
PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
childSize = infoPtr->nWidth;
}
else
{
wndSize = wndRect.bottom - wndRect.top;
PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
childSize = infoPtr->nHeight;
}
@ -415,68 +416,6 @@ PAGER_WindowPosChanging(PAGER_INFO* infoPtr, WINDOWPOS *winpos)
return DefWindowProcW (infoPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos);
}
static INT
PAGER_SetFixedWidth(PAGER_INFO* infoPtr)
{
/* Must set the non-scrollable dimension to be less than the full height/width
* so that NCCalcSize is called. The Microsoft docs mention 3/4 factor for button
* size, and experimentation shows that the effect is almost right. */
RECT wndRect;
INT delta, h;
GetWindowRect(infoPtr->hwndSelf, &wndRect);
/* see what the app says for btn width */
PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
if (infoPtr->dwStyle & CCS_NORESIZE)
{
delta = wndRect.right - wndRect.left - infoPtr->nWidth;
if (delta > infoPtr->nButtonSize)
infoPtr->nWidth += 4 * infoPtr->nButtonSize / 3;
else if (delta > 0)
infoPtr->nWidth += infoPtr->nButtonSize / 3;
}
h = wndRect.bottom - wndRect.top + infoPtr->nButtonSize;
TRACE("[%p] infoPtr->nWidth set to %d\n",
infoPtr->hwndSelf, infoPtr->nWidth);
return h;
}
static INT
PAGER_SetFixedHeight(PAGER_INFO* infoPtr)
{
/* Must set the non-scrollable dimension to be less than the full height/width
* so that NCCalcSize is called. The Microsoft docs mention 3/4 factor for button
* size, and experimentation shows that the effect is almost right. */
RECT wndRect;
INT delta, w;
GetWindowRect(infoPtr->hwndSelf, &wndRect);
/* see what the app says for btn height */
PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
if (infoPtr->dwStyle & CCS_NORESIZE)
{
delta = wndRect.bottom - wndRect.top - infoPtr->nHeight;
if (delta > infoPtr->nButtonSize)
infoPtr->nHeight += infoPtr->nButtonSize;
else if (delta > 0)
infoPtr->nHeight += infoPtr->nButtonSize / 3;
}
w = wndRect.right - wndRect.left + infoPtr->nButtonSize;
TRACE("[%p] infoPtr->nHeight set to %d\n",
infoPtr->hwndSelf, infoPtr->nHeight);
return w;
}
/******************************************************************
* For the PGM_RECALCSIZE message (but not the other uses in *
* this module), the native control does only the following: *
@ -561,28 +500,14 @@ PAGER_SetButtonSize (PAGER_INFO* infoPtr, INT iButtonSize)
static LRESULT
PAGER_SetChild (PAGER_INFO* infoPtr, HWND hwndChild)
{
INT hw;
infoPtr->hwndChild = IsWindow (hwndChild) ? hwndChild : 0;
if (infoPtr->hwndChild)
{
TRACE("[%p] hwndChild=%p\n", infoPtr->hwndSelf, infoPtr->hwndChild);
if (infoPtr->dwStyle & PGS_HORZ) {
hw = PAGER_SetFixedHeight(infoPtr);
/* adjust non-scrollable dimension to fit the child */
SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, hw, infoPtr->nHeight,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
SWP_NOSIZE | SWP_NOACTIVATE);
}
else {
hw = PAGER_SetFixedWidth(infoPtr);
/* adjust non-scrollable dimension to fit the child */
SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, infoPtr->nWidth, hw,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
SWP_NOSIZE | SWP_NOACTIVATE);
}
SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
/* position child within the page scroller */
SetWindowPos(infoPtr->hwndChild, HWND_TOP,
@ -721,11 +646,12 @@ PAGER_NCCalcSize(PAGER_INFO* infoPtr, WPARAM wParam, LPRECT lpRect)
MapWindowPoints (0, infoPtr->hwndSelf, (LPPOINT)&rcChild, 2); /* FIXME: RECT != 2 POINTS */
GetWindowRect (infoPtr->hwndSelf, &rcWindow);
infoPtr->nWidth = lpRect->right - lpRect->left;
infoPtr->nHeight = lpRect->bottom - lpRect->top;
PAGER_CalcSize( infoPtr );
if (infoPtr->dwStyle & PGS_HORZ)
{
infoPtr->nWidth = lpRect->right - lpRect->left;
PAGER_CalcSize (infoPtr, &infoPtr->nWidth, TRUE);
if (infoPtr->TLbtnState && (lpRect->left + infoPtr->nButtonSize < lpRect->right))
lpRect->left += infoPtr->nButtonSize;
if (infoPtr->BRbtnState && (lpRect->right - infoPtr->nButtonSize > lpRect->left))
@ -733,9 +659,6 @@ PAGER_NCCalcSize(PAGER_INFO* infoPtr, WPARAM wParam, LPRECT lpRect)
}
else
{
infoPtr->nHeight = lpRect->bottom - lpRect->top;
PAGER_CalcSize (infoPtr, &infoPtr->nHeight, FALSE);
if (infoPtr->TLbtnState && (lpRect->top + infoPtr->nButtonSize < lpRect->bottom))
lpRect->top += infoPtr->nButtonSize;
if (infoPtr->BRbtnState && (lpRect->bottom - infoPtr->nButtonSize > lpRect->top))