Exemple #1
0
//+---------------------------------------------------------------------------
//
//  Member:     CScrollbar::GetPart
//              
//  Synopsis:   Return the scroll bar part hit by the given test point.
//              
//  Arguments:  direction       0 for horizontal scroll bar, 1 for vertical
//              rcScrollbar     scroll bar bounds
//              ptHit           test point
//              contentSize     size of content controlled by scroll bar
//              containerSize   size of container
//              scrollAmount    current scroll amount
//              buttonWidth     width of scroll bar buttons
//              fRightToLeft    The text flow is RTL...0,0 is at top right
//              
//  Returns:    The scroll bar part hit, or SBP_NONE if nothing was hit.
//              
//  Notes:      
//              
//----------------------------------------------------------------------------
CScrollbar::SCROLLBARPART CScrollbar::GetPart(
	int				direction,
	const CRect&	rcScrollbar,
	const CPoint&	ptHit,
	long			contentSize,
	long			containerSize,
	long			scrollAmount,
	long			buttonWidth,
	CDrawInfo*		pDI,
	BOOL			fRightToLeft)
{
	if(!rcScrollbar.Contains(ptHit))
	{
		return SBP_NONE;
	}

	// adjust button width if there isn't room for both buttons at full size
	long scaledButtonWidth = GetScaledButtonWidth(direction, rcScrollbar, buttonWidth);

	// now test just the axis that matters
	long x = ptHit[direction];

	if(x < rcScrollbar.TopLeft()[direction]+scaledButtonWidth)
	{
		return SBP_PREVBUTTON;
	}

	if(x >= rcScrollbar.BottomRight()[direction]-scaledButtonWidth)
	{
		return SBP_NEXTBUTTON;
	}

	// NOTE: if there is no thumb, return SBP_TRACK
	CRect rcThumb;
	GetPartRect(
		&rcThumb,
		SBP_THUMB,
		direction,
		rcScrollbar,
		contentSize,
		containerSize,
		scrollAmount,
		buttonWidth,
		pDI,
		fRightToLeft);
	if(rcThumb.IsEmpty())
	{
		return SBP_TRACK;
	}

	if(x < rcThumb.TopLeft()[direction])
	{
		return SBP_PREVTRACK;
	}
	if(x >= rcThumb.BottomRight()[direction])
	{
		return SBP_NEXTTRACK;
	}

	return SBP_THUMB;
}