Scrollbar improvements

svn path=/trunk/; revision=3885
This commit is contained in:
Jason Filby 2002-12-21 19:25:41 +00:00
parent afe60dcdbf
commit 69ccaa8434
4 changed files with 164 additions and 162 deletions

View file

@ -1,4 +1,4 @@
/* $Id: scrollbar.c,v 1.4 2002/11/24 20:13:43 jfilby Exp $
/* $Id: scrollbar.c,v 1.5 2002/12/21 19:23:50 jfilby Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -84,7 +84,7 @@ WINBOOL STDCALL
GetScrollBarInfo (HWND hwnd, LONG idObject, PSCROLLBARINFO psbi)
{
int ret = NtUserGetScrollBarInfo (hwnd, idObject, psbi);
DbgPrint("GetScrollBarInfo: psbi: %08x\n", psbi);
return ret;
}
@ -111,7 +111,8 @@ SCROLL_DrawInterior (HWND hwnd, HDC hdc, INT nBar,
}
else
{
/* hBrush = DefWndControlColor (hdc, CTLCOLOR_SCROLLBAR); */
/* hBrush = NtUserGetControlColor (hdc, CTLCOLOR_SCROLLBAR); FIXME */ /* DefWndControlColor */
hBrush = GetSysColorBrush(COLOR_SCROLLBAR);
}
hSavePen = SelectObject (hdc, GetSysColorPen (COLOR_WINDOWFRAME));
@ -119,7 +120,7 @@ SCROLL_DrawInterior (HWND hwnd, HDC hdc, INT nBar,
/* Calculate the scroll rectangle */
r = *rect;
DbgPrint ("[DrawInterior:r1:%d,%d,%d,%d]", r.left, r.top, r.right, r.bottom);
if (nBar == SB_VERT)
{
r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
@ -162,7 +163,6 @@ SCROLL_DrawInterior (HWND hwnd, HDC hdc, INT nBar,
r.right = r.left + thumbSize;
}
DbgPrint ("[DrawInterior:r2:%d,%d,%d,%d]", r.left, r.top, r.right, r.bottom);
/* Draw the thumb */
DrawEdge (hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE);
@ -178,26 +178,24 @@ SCROLL_DrawMovingThumb (HDC hdc, RECT * rect, int nBar,
{
INT pos = SCROLL_TrackingPos;
INT max_size;
DbgPrint ("[SCROLL_DrawMovingThumb:0 - no PAUSE!]");
/* for (;;); */
if (nBar == SB_VERT)
max_size = rect->bottom - rect->top;
else if (nBar == SB_HORZ)
max_size = rect->right - rect->left;
max_size -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
DbgPrint ("[SCROLL_DrawMovingThumb:1]");
if (pos < (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
pos = (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
else if (pos > max_size)
pos = max_size;
DbgPrint ("[SCROLL_DrawMovingThumb:2]");
SCROLL_DrawInterior (SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
rect, arrowSize, thumbSize, pos,
0, FALSE, FALSE);
DbgPrint ("[SCROLL_DrawMovingThumb:3]");
SCROLL_MovingThumb = !SCROLL_MovingThumb;
DbgPrint ("[SCROLL_DrawMovingThumb:e]");
}
/* Ported from WINE20020904 */
@ -229,7 +227,7 @@ SCROLL_DrawArrows (HDC hdc, PSCROLLBARINFO info,
DrawFrameControl (hdc, &r, DFC_SCROLL,
scrollDirFlag1 | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0)
/* | (info->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0) */
/* | (info.flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0) */
);
r = *rect;
if (nBar == SB_VERT)
@ -238,7 +236,7 @@ SCROLL_DrawArrows (HDC hdc, PSCROLLBARINFO info,
r.left = r.right - arrowSize;
DrawFrameControl (hdc, &r, DFC_SCROLL,
scrollDirFlag2 | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0)
/* | (info->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) */
/* | (info.flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) */
);
}
@ -248,64 +246,62 @@ void
SCROLL_DrawScrollBar (HWND hwnd, HDC hdc, INT nBar,
BOOL arrows, BOOL interior)
{
INT arrowSize, thumbSize, thumbPos;
INT arrowSize = 20, thumbSize = 20, thumbPos = 1; /* FIXME: Should not be assign values, but rather obtaining */
/* WND *wndPtr = WIN_FindWndPtr( hwnd ); */
PSCROLLBARINFO info;
SCROLLBARINFO info;
BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
DbgPrint("[SCROLL_DrawScrollBar:0]");
GetScrollBarInfo (hwnd, nBar, info);
DbgPrint("[SCROLL_DrawScrollBar:1]");
DbgPrint("info: %08x\n", info);
DbgPrint("info->rcScrollBar: %d,%d,%d,%d\n", info->rcScrollBar.left, info->rcScrollBar.top, info->rcScrollBar.right, info->rcScrollBar.bottom);
info.cbSize = sizeof(SCROLLBARINFO);
GetScrollBarInfo (hwnd, nBar, &info);
/* if (!wndPtr || !info ||
((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
if (!WIN_IsWindowDrawable( hwnd, FALSE )) goto END;
hwnd = wndPtr->hwndSelf; */ /* make it a full handle */
if (IsRectEmpty (&(info->rcScrollBar))) goto END;
DbgPrint("[SCROLL_DrawScrollBar:2]");
if (IsRectEmpty (&(info.rcScrollBar))) goto END;
if (Save_SCROLL_MovingThumb && (SCROLL_TrackingWin == hwnd) && (SCROLL_TrackingBar == nBar))
{
DbgPrint("[SCROLL_DrawScrollBar:2a]");
SCROLL_DrawMovingThumb (hdc, &info->rcScrollBar, nBar, arrowSize, thumbSize);
SCROLL_DrawMovingThumb (hdc, &(info.rcScrollBar), nBar, arrowSize, thumbSize);
}
DbgPrint("[SCROLL_DrawScrollBar:3]");
/* Draw the arrows */
if (arrows && arrowSize)
{
if (SCROLL_trackVertical == TRUE /* && GetCapture () == hwnd */)
{
SCROLL_DrawArrows (hdc, info, &info->rcScrollBar, arrowSize, nBar,
SCROLL_DrawArrows (hdc, &info, &(info.rcScrollBar), arrowSize, nBar,
(SCROLL_trackHitTest == SCROLL_TOP_ARROW),
(SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW));
}
else
{
SCROLL_DrawArrows (hdc, info, &info->rcScrollBar, arrowSize, nBar, FALSE, FALSE);
SCROLL_DrawArrows (hdc, &info, &(info.rcScrollBar), arrowSize, nBar, FALSE, FALSE);
}
}
if (interior)
{
SCROLL_DrawInterior (hwnd, hdc, nBar, &info->rcScrollBar, arrowSize, thumbSize,
SCROLL_DrawInterior (hwnd, hdc, nBar, &(info.rcScrollBar), arrowSize, thumbSize,
thumbPos, /* info->flags FIXME */ 0, FALSE, FALSE);
}
if (Save_SCROLL_MovingThumb &&
(SCROLL_TrackingWin == hwnd) && (SCROLL_TrackingBar == nBar))
SCROLL_DrawMovingThumb (hdc, &info->rcScrollBar, nBar, arrowSize, thumbSize);
SCROLL_DrawMovingThumb (hdc, &info.rcScrollBar, nBar, arrowSize, thumbSize);
/* if scroll bar has focus, reposition the caret */
/* if (hwnd == GetFocus () && (nBar == SB_CTL))
{
if (nBar == SB_HORZ)
{
SetCaretPos (thumbPos + 1, info->rcScrollBar.top + 1);
SetCaretPos (thumbPos + 1, info.rcScrollBar.top + 1);
}
else if (nBAR == SB_VERT)
{
SetCaretPos (info->rcScrollBar.top + 1, thumbPos + 1);
SetCaretPos (info.rcScrollBar.top + 1, thumbPos + 1);
}
} */
END:
@ -359,7 +355,6 @@ SetScrollRange (HWND hWnd,
WINBOOL STDCALL
ShowScrollBar (HWND hWnd, int wBar, WINBOOL bShow)
{
DbgPrint("[ShowScrollBar]");
NtUserShowScrollBar (hWnd, wBar, bShow);
return TRUE;
}

View file

@ -1,4 +1,4 @@
/* $Id: scrollbar.c,v 1.1 2002/11/24 20:15:37 jfilby Exp $
/* $Id: scrollbar.c,v 1.2 2002/12/21 19:24:51 jfilby Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -35,25 +35,21 @@
* the top. Return TRUE if the scrollbar is vertical, FALSE if horizontal.
*/
static BOOL
SCROLL_GetScrollBarRect (PWINDOW_OBJECT Window, INT nBar, PRECT lprect,
PINT arrowSize, PINT thumbSize, PINT thumbPos)
SCROLL_GetScrollBarRect (PWINDOW_OBJECT Window, INT nBar, PRECT lprect /* ,
PINT arrowSize, PINT thumbSize, PINT thumbPos */ )
{
INT pixels;
INT pixels, thumbSize, arrowSize;
BOOL vertical;
RECT ClientRect;
RECT ClientRect = Window->ClientRect;
RECT WindowRect = Window->WindowRect;
ULONG Style;
DbgPrint("[SCROLL_GetScrollBarRect]");
W32kGetClientRect (Window, &ClientRect);
DbgPrint("[WindowRect:%d,%d,%d,%d]\n", Window->WindowRect.left, Window->WindowRect.top, Window->WindowRect.right, Window->WindowRect.bottom);
DbgPrint("[ClientRect:%d,%d,%d,%d]\n", ClientRect.left, ClientRect.top, ClientRect.right, ClientRect.bottom);
switch (nBar)
{
case SB_HORZ:
DbgPrint ("[SCROLL_GetScrollBarRect:SB_HORZ]");
lprect->left = ClientRect.left - Window->WindowRect.left;
lprect->top = ClientRect.bottom - Window->WindowRect.top;
lprect->right = ClientRect.right - Window->WindowRect.left;
lprect->left = ClientRect.left - WindowRect.left;
lprect->top = ClientRect.bottom - WindowRect.top;
lprect->right = ClientRect.right - WindowRect.left;
lprect->bottom = lprect->top + NtUserGetSystemMetrics (SM_CYHSCROLL);
if (Window->Style & WS_BORDER)
{
@ -66,15 +62,10 @@ DbgPrint("[ClientRect:%d,%d,%d,%d]\n", ClientRect.left, ClientRect.top, ClientRe
break;
case SB_VERT:
DbgPrint ("[SCROLL_GetScrollBarRect:SB_VERT]\n");
/* lprect->left = ClientRect.right - Window->WindowRect.left;
lprect->top = ClientRect.top - Window->WindowRect.top;
lprect->left = ClientRect.right - WindowRect.left;
lprect->top = ClientRect.top - WindowRect.top;
lprect->right = lprect->left + NtUserGetSystemMetrics (SM_CXVSCROLL);
lprect->bottom = ClientRect.bottom - WindowRect.top; */
lprect->left = Window->WindowRect.left + ClientRect.right;
lprect->top = Window->WindowRect.bottom - ClientRect.bottom;
lprect->right = lprect->left + NtUserGetSystemMetrics (SM_CXVSCROLL);
lprect->bottom = Window->WindowRect.bottom;
lprect->bottom = ClientRect.bottom - WindowRect.top;
if (Window->Style & WS_BORDER)
{
lprect->top--;
@ -82,25 +73,15 @@ DbgPrint("[ClientRect:%d,%d,%d,%d]\n", ClientRect.left, ClientRect.top, ClientRe
}
else if (Window->Style & WS_HSCROLL)
lprect->bottom++;
DbgPrint ("[VERTDIMEN:%d,%d,%d,%d]\n", lprect->left, lprect->top,
lprect->right, lprect->bottom);
DbgPrint ("[Window:%d,%d,%d,%d]\n", Window->WindowRect.left, Window->WindowRect.top,
Window->WindowRect.right, Window->WindowRect.bottom);
DbgPrint ("[Client:%d,%d,%d,%d]\n", ClientRect.left, ClientRect.top,
ClientRect.right, ClientRect.bottom);
DbgPrint ("[NtUserGetSystemMetrics(SM_CXVSCROLL):%d]\n",
NtUserGetSystemMetrics (SM_CXVSCROLL));
vertical = TRUE;
break;
case SB_CTL:
DbgPrint ("[SCROLL_GetScrollBarRect:SB_CTL]");
W32kGetClientRect (Window, lprect);
vertical = ((Window->Style & SBS_VERT) != 0);
break;
default:
DbgPrint ("[SCROLL_GetScrollBarRect:FAIL]");
W32kReleaseWindowObject(Window);
return FALSE;
}
@ -112,19 +93,16 @@ DbgPrint("[ClientRect:%d,%d,%d,%d]\n", ClientRect.left, ClientRect.top, ClientRe
if (pixels <= 2 * NtUserGetSystemMetrics (SM_CXVSCROLL) + SCROLL_MIN_RECT)
{
if (pixels > SCROLL_MIN_RECT)
*arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
else
*arrowSize = 0;
*thumbPos = *thumbSize = 0;
info.dxyLineButton = info.xyThumbTop = info.xyThumbBottom = 0;
}
else
{
/* PSCROLLBARINFO info;
SCROLLBARINFO info;
info.cbSize = sizeof(SCROLLBARINFO);
NtUserGetScrollBarInfo (hWnd, nBar, info); recursive loop.. since called function calls this function */
SCROLL_GetScrollBarInfo (Window, nBar, &info);
*arrowSize = NtUserGetSystemMetrics (SM_CXVSCROLL);
arrowSize = NtUserGetSystemMetrics (SM_CXVSCROLL);
pixels -=
(2 * (NtUserGetSystemMetrics (SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
/* if (info->Page)
@ -150,109 +128,78 @@ DbgPrint("[ClientRect:%d,%d,%d,%d]\n", ClientRect.left, ClientRect.top, ClientRe
+ MulDiv(pixels, (info->CurVal-info->MinVal),(max - info->MinVal));
} */
}
W32kReleaseWindowObject(Window);
return vertical;
}
DWORD SCROLL_CreateScrollBar(PWINDOW_OBJECT Window, LONG idObject)
{
PSCROLLBARINFO psbi;
LRESULT Result;
int thumbSize = 20, arrowSize = 20, thumbPos = 1;
Result = WinPosGetNonClientSize(Window->Self,
&Window->WindowRect,
&Window->ClientRect);
psbi = ExAllocatePool(NonPagedPool, sizeof(SCROLLBARINFO));
switch(idObject)
{
case SB_HORZ:
Window->pHScroll = psbi;
break;
case SB_VERT:
Window->pVScroll = psbi;
break;
case SB_CTL:
Window->wExtra = psbi;
break;
default:
return FALSE;
}
SCROLL_GetScrollBarRect (Window, idObject, &(psbi->rcScrollBar) /* , &arrowSize, &thumbSize, &thumbPos */ );
return 0;
}
DWORD SCROLL_GetScrollBarInfo(PWINDOW_OBJECT Window, LONG idObject, PSCROLLBARINFO psbi)
{
switch(idObject)
{
case SB_HORZ:
memcpy(psbi, Window->pHScroll, psbi->cbSize);
break;
case SB_VERT:
memcpy(psbi, Window->pVScroll, psbi->cbSize);
break;
case SB_CTL:
memcpy(psbi, Window->wExtra, psbi->cbSize);
break;
default:
W32kReleaseWindowObject(Window);
return FALSE;
}
return TRUE;
}
DWORD
STDCALL
NtUserGetScrollBarInfo(HWND hWnd, LONG idObject, PSCROLLBARINFO psbi)
{
PWINDOW_OBJECT Window = W32kGetWindowObject(hWnd);
int thumbSize = 20, arrowSize = 20, thumbPos = 0;
if (!Window) return FALSE;
switch(idObject)
{
case SB_HORZ: psbi = Window->pHScroll; break;
case SB_VERT: psbi = Window->pVScroll; break;
case SB_CTL: psbi = Window->wExtra; break;
default:
W32kReleaseWindowObject(Window);
return FALSE;
}
SCROLL_GetScrollBarInfo(Window, idObject, psbi);
if (!psbi) /* Create the info structure if needed */
{
if ((psbi = ExAllocatePool(NonPagedPool, sizeof(SCROLLBARINFO))))
{
DbgPrint("Creating PSCROLLBARINFO for %d - psbi: %08x\n", idObject, psbi);
SCROLL_GetScrollBarRect (Window, idObject, &(psbi->rcScrollBar), &arrowSize, &thumbSize, &thumbPos);
DbgPrint("NtUserGetScrollBarInfo: Creating with rect (%d,%d,%d,%d)\n",
psbi->rcScrollBar.left, psbi->rcScrollBar.top, psbi->rcScrollBar.right, psbi->rcScrollBar.bottom);
if (idObject == SB_HORZ) Window->pHScroll = psbi;
else Window->pVScroll = psbi;
}
/* if (!hUpArrow) SCROLL_LoadBitmaps(); FIXME: This must be moved somewhere in user32 code */
}
DbgPrint("z1: psbi: %08x\n", psbi);
W32kReleaseWindowObject(Window);
DbgPrint("z2: psbi: %08x\n", psbi);
return TRUE;
}
/* Ported from WINE20020904 */
BOOL
SCROLL_ShowScrollBar (HWND hwnd, INT nBar, BOOL fShowH, BOOL fShowV)
{
PWINDOW_OBJECT Window = W32kGetWindowObject(hwnd);
switch (nBar)
{
case SB_CTL:
NtUserShowWindow (hwnd, fShowH ? SW_SHOW : SW_HIDE);
return TRUE;
case SB_BOTH:
case SB_HORZ:
if (fShowH)
{
fShowH = !(Window->Style & WS_HSCROLL);
Window->Style |= WS_HSCROLL;
}
else /* hide it */
{
fShowH = (Window->Style & WS_HSCROLL);
Window->Style &= ~WS_HSCROLL;
}
if (nBar == SB_HORZ)
{
fShowV = FALSE;
break;
}
/* fall through */
case SB_VERT:
if (fShowV)
{
fShowV = !(Window->Style & WS_VSCROLL);
Window->Style |= WS_VSCROLL;
}
else /* hide it */
{
fShowV = (Window->Style & WS_VSCROLL);
Window->Style &= ~WS_VSCROLL;
}
if (nBar == SB_VERT)
fShowH = FALSE;
break;
default:
return FALSE; /* Nothing to do! */
}
if (fShowH || fShowV) /* frame has been changed, let the window redraw itself */
{
NtUserSetWindowPos (hwnd, 0, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
return TRUE;
}
return FALSE; /* no frame changes */
}
DWORD
STDCALL
NtUserEnableScrollBar(
@ -293,14 +240,66 @@ NtUserSetScrollInfo(
return 0;
}
/* Ported from WINE20020904 (SCROLL_ShowScrollBar) */
DWORD
STDCALL
NtUserShowScrollBar(HWND hWnd, int wBar, DWORD bShow)
{
DbgPrint("[NtUserShowScrollBar:%d]", bShow);
SCROLL_ShowScrollBar (hWnd, wBar, (wBar == SB_VERT) ? 0 : bShow, (wBar == SB_HORZ) ? 0 : bShow);
BOOL fShowV = (wBar == SB_VERT) ? 0 : bShow;
BOOL fShowH = (wBar == SB_HORZ) ? 0 : bShow;
PWINDOW_OBJECT Window = W32kGetWindowObject(hWnd);
return 0;
switch (wBar)
{
case SB_CTL:
NtUserShowWindow (hWnd, fShowH ? SW_SHOW : SW_HIDE);
return TRUE;
case SB_BOTH:
case SB_HORZ:
if (fShowH)
{
fShowH = !(Window->Style & WS_HSCROLL);
Window->Style |= WS_HSCROLL;
}
else /* hide it */
{
fShowH = (Window->Style & WS_HSCROLL);
Window->Style &= ~WS_HSCROLL;
}
if (wBar == SB_HORZ)
{
fShowV = FALSE;
break;
}
/* fall through */
case SB_VERT:
if (fShowV)
{
fShowV = !(Window->Style & WS_VSCROLL);
Window->Style |= WS_VSCROLL;
}
else /* hide it */
{
fShowV = (Window->Style & WS_VSCROLL);
Window->Style &= ~WS_VSCROLL;
}
if (wBar == SB_VERT)
fShowH = FALSE;
break;
default:
return FALSE; /* Nothing to do! */
}
if (fShowH || fShowV) /* frame has been changed, let the window redraw itself */
{
NtUserSetWindowPos (hWnd, 0, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
return TRUE;
}
return FALSE; /* no frame changes */
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: window.c,v 1.19 2002/10/31 00:03:31 dwelch Exp $
/* $Id: window.c,v 1.20 2002/12/21 19:24:51 jfilby Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -497,6 +497,12 @@ NtUserCreateWindowEx(DWORD dwExStyle,
/* FIXME: Initialize the window menu. */
/* Initialize the window's scrollbars */
if (dwStyle & WS_VSCROLL)
SCROLL_CreateScrollBar(WindowObject, SB_VERT);
if (dwStyle & WS_HSCROLL)
SCROLL_CreateScrollBar(WindowObject, SB_HORZ);
/* Send a NCCREATE message. */
Cs.lpCreateParams = lpParam;
Cs.hInstance = hInstance;

View file

@ -121,10 +121,12 @@ W32kLineTo(HDC hDC,
ASSERT( pen );
// not yet implemented ASSERT( reg );
/* Draw the line according to the DC origin */
ret = EngLineTo(SurfObj,
NULL, // ClipObj
PenToBrushObj(dc, pen),
dc->w.CursPosX, dc->w.CursPosY, XEnd, YEnd,
dc->w.DCOrgX + dc->w.CursPosX, dc->w.DCOrgY + dc->w.CursPosY,
dc->w.DCOrgX + XEnd, dc->w.DCOrgY + YEnd,
reg, // Bounding rectangle
dc->w.ROPmode); // MIX