📄 bcgpbarcontainer.cpp
字号:
dLeftPercent = 50;
}
if (nDelta > 0)
{
rectFinalLeft.bottom = rectFinalLeft.top + rectLeft.Height () +
(int)( (double) (nDelta * (100 - dLeftPercent)) / 100.) ;
}
else if (nDelta < 0)
{
rectFinalLeft.bottom = rectFinalLeft.top + rectLeft.Height () +
(int)( (double) nDelta * (dLeftPercent) / 100.);
}
else
{
rectFinalLeft.bottom = rectFinalLeft.top + rectLeft.Height ();
if (nPercent != -1)
{
dLeftPercent = nPercent;
}
}
rectFinalSlider.top = rectFinalLeft.bottom;
rectFinalSlider.bottom = rectFinalSlider.top + m_pSlider->GetWidth ();
rectFinalRight.top = rectFinalSlider.bottom;
}
else
{
int nPercent = -1;
if ((rectLeft.Width () + rectRight.Width ()) > rectContainer.Width () ||
rectLeft.IsRectEmpty () || rectRight.IsRectEmpty ())
{
if (rectLeft.Width () == rectContainer.Width ())
{
nPercent = 50;
if (m_pBarRightBottom != NULL)
{
nPercent = m_pBarRightBottom->GetLastPercentInContainer ();
}
else if (m_pRightContainer != NULL)
{
nPercent = m_pRightContainer->GetRecentPercent ();
}
if (nPercent == 100 || nPercent == 0)
{
nPercent = 50;
}
rectLeft.right = rectLeft.left +
rectContainer.Width () -
((rectContainer.Width () * nPercent) / 100);
nPercent = 100 - nPercent;
}
else if (rectRight.Width () == rectContainer.Width ())
{
nPercent = 50;
if (m_pBarLeftTop != NULL)
{
nPercent = m_pBarLeftTop->GetLastPercentInContainer ();
}
else if (m_pLeftContainer != NULL)
{
nPercent = m_pLeftContainer->GetRecentPercent ();
}
if (nPercent == 100 || nPercent == 0)
{
nPercent = 50;
}
rectLeft.right = rectLeft.left +
((rectContainer.Width () * nPercent) / 100);
}
}
int nDelta = rect.Width () - rectContainer.Width ();
dLeftPercent = ((double) rectLeft.Width ()) /
rectContainer.Width () * 100;
if (dLeftPercent == 100 || dLeftPercent == 0)
{
dLeftPercent = 50;
}
if (nDelta > 0)
{
rectFinalLeft.right = rectFinalLeft.left + rectLeft.Width () +
(int) (((double) nDelta * (100 - dLeftPercent)) / 100.);
}
else if (nDelta < 0)
{
rectFinalLeft.right = rectFinalLeft.left + rectLeft.Width () +
(int) (((double) nDelta * dLeftPercent) / 100.);
}
else
{
rectFinalLeft.right = rectFinalLeft.left + rectLeft.Width ();
if (nPercent != -1)
{
dLeftPercent = nPercent;
}
}
rectFinalSlider.left = rectFinalLeft.right;
rectFinalSlider.right = rectFinalSlider.left + m_pSlider->GetWidth ();
rectFinalRight.left = rectFinalSlider.right;
}
if (m_pBarLeftTop != NULL)
{
hdwp = m_pBarLeftTop->MoveWindow (rectFinalLeft, bRedraw, hdwp);
m_pBarLeftTop->SetLastPercentInContainer ((int) dLeftPercent);
}
if (m_pLeftContainer != NULL)
{
m_pLeftContainer->ResizeContainer (rectFinalLeft, hdwp, bRedraw);
m_pLeftContainer->SetRecentPercent ((int) dLeftPercent);
}
if (m_pBarRightBottom != NULL)
{
hdwp = m_pBarRightBottom->MoveWindow (rectFinalRight, bRedraw, hdwp);
m_pBarRightBottom->SetLastPercentInContainer (100 - (int) dLeftPercent);
}
if (m_pRightContainer != NULL)
{
m_pRightContainer->ResizeContainer (rectFinalRight, hdwp, bRedraw);
m_pRightContainer->SetRecentPercent (100 - (int) dLeftPercent);
}
if (m_pSlider->IsBarVisible ())
{
hdwp = m_pSlider->MoveWindow (rectFinalSlider, bRedraw, hdwp);
}
}
}
//-----------------------------------------------------------------------------------//
int CBCGPBarContainer::StretchContainer (int nOffset, BOOL bStretchHorz, BOOL bLeftBar,
BOOL bMoveSlider, HDWP& hdwp)
{
ASSERT_VALID (this);
int nDirection = nOffset < 0 ? -1 : 1;
CSize sizeStretch (0, 0);
bStretchHorz ? sizeStretch.cx = nOffset : sizeStretch.cy = nOffset;
int nAvailSpace = bStretchHorz ? CalcAvailableSpace (sizeStretch, bLeftBar).cx :
CalcAvailableSpace (sizeStretch, bLeftBar).cy;
// set the sign here
int nActualSize = nDirection * min (abs (nOffset), abs (nAvailSpace));
if (abs (nActualSize) == 0)
{
return 0;
}
// check whether the container's native slider has the same
// orientation as stretch direction
if (m_pSlider == NULL || (m_pSlider->IsHorizontal () && bStretchHorz ||
!m_pSlider->IsHorizontal () && !bStretchHorz))
{
// just use minimum of the avail. and req to stretch both bars and the
// slider
ResizeBar (nActualSize, m_pBarLeftTop, m_pLeftContainer, bStretchHorz, bLeftBar, hdwp);
ResizeBar (nActualSize, m_pBarRightBottom, m_pRightContainer, bStretchHorz, bLeftBar, hdwp);
// resize the slider
if (bMoveSlider && m_pSlider != NULL)
{
CRect rectSlider;
m_pSlider->GetWindowRect (rectSlider);
if (m_pSlider->IsHorizontal ())
{
bLeftBar ? rectSlider.right += nActualSize :
rectSlider.left += nActualSize;
}
else
{
bLeftBar ? rectSlider.bottom += nActualSize :
rectSlider.top += nActualSize;
}
if (m_pSlider->IsBarVisible ())
{
m_pSlider->GetParent ()->ScreenToClient (rectSlider);
m_pSlider->MoveWindow (rectSlider, FALSE, hdwp);
}
}
}
else
{
// treat bar's available space individually
int nLeftAvailOffset = CalcAvailableBarSpace (nOffset, m_pBarLeftTop, m_pLeftContainer, bLeftBar);
int nRigthAvailOffset = CalcAvailableBarSpace (nOffset, m_pBarRightBottom, m_pRightContainer, bLeftBar);
int nSliderOffset = 0;
int nBarOffset = nActualSize;
if (abs (nLeftAvailOffset) == abs (nRigthAvailOffset))
{
nSliderOffset = (abs (nLeftAvailOffset) / 2 + 1) * nDirection;
}
else
{
nSliderOffset = nActualSize;
}
CPoint pt (0, 0);
bStretchHorz ? pt.x = nSliderOffset : pt.y = nSliderOffset;
if (bMoveSlider)
{
m_pSlider->MoveSlider (pt);
}
if (bLeftBar)
{
ResizeBar (nBarOffset, m_pBarRightBottom, m_pRightContainer, bStretchHorz, bLeftBar, hdwp);
}
else
{
ResizeBar (nBarOffset, m_pBarLeftTop, m_pLeftContainer, bStretchHorz, bLeftBar, hdwp);
}
}
return nActualSize;
}
//-----------------------------------------------------------------------------------//
int CBCGPBarContainer::OnMoveInternalSlider (int nOffset, HDWP& hdwp)
{
ASSERT_VALID (this);
ASSERT_VALID (m_pSlider);
CRect rectLeft; rectLeft.SetRectEmpty ();
CRect rectRight; rectRight.SetRectEmpty ();
CSize sizeMinLeft;
CSize sizeMinRight;
if (m_pBarLeftTop != NULL)
{
m_pBarLeftTop->GetWindowRect (rectLeft);
m_pBarLeftTop->GetMinSize (sizeMinLeft);
}
if (m_pLeftContainer != NULL)
{
m_pLeftContainer->GetWindowRect (rectLeft);
m_pLeftContainer->GetMinSize (sizeMinLeft);
}
if (m_pBarRightBottom != NULL)
{
m_pBarRightBottom->GetWindowRect (rectRight);
m_pBarRightBottom->GetMinSize (sizeMinRight);
}
if (m_pRightContainer != NULL)
{
m_pRightContainer->GetWindowRect (rectRight);
m_pRightContainer->GetMinSize (sizeMinRight);
}
if (!rectLeft.IsRectEmpty ())
{
if (IsSliderHorz ())
{
rectLeft.bottom += nOffset;
if (rectLeft.Height () < sizeMinLeft.cy)
{
rectLeft.bottom = rectLeft.top + sizeMinLeft.cy;
}
}
else
{
rectLeft.right += nOffset;
if (rectLeft.Width () < sizeMinLeft.cx)
{
rectLeft.right = rectLeft.left + sizeMinLeft.cx;
}
}
}
if (!rectRight.IsRectEmpty ())
{
if (IsSliderHorz ())
{
rectRight.top += nOffset;
if (rectRight.Height () < sizeMinRight.cy)
{
rectRight.top = rectRight.bottom - sizeMinRight.cy;
}
}
else
{
rectRight.left += nOffset;
if (rectRight.Width () < sizeMinRight.cx)
{
rectRight.left = rectRight.right - sizeMinRight.cx;
}
}
}
m_pSlider->GetParent ()->ScreenToClient (rectLeft);
m_pSlider->GetParent ()->ScreenToClient (rectRight);
if (m_pBarLeftTop != NULL)
{
hdwp = m_pBarLeftTop->MoveWindow (rectLeft, TRUE, hdwp);
}
if (m_pLeftContainer != NULL)
{
m_pLeftContainer->ResizeContainer (rectLeft, hdwp);
}
if (m_pBarRightBottom != NULL)
{
hdwp = m_pBarRightBottom->MoveWindow (rectRight, TRUE, hdwp);
}
if (m_pRightContainer != NULL)
{
m_pRightContainer->ResizeContainer (rectRight, hdwp);
}
return nOffset;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::ResizeBar (int nOffset, CBCGPControlBar* pBar,
CBCGPBarContainer* pContainer,
BOOL bHorz,
BOOL bLeftBar, HDWP& hdwp)
{
ASSERT_VALID (this);
if (pBar != NULL)
{
CRect rectBar;
pBar->GetWindowRect (rectBar);
if (bHorz)
{
bLeftBar ? rectBar.bottom += nOffset : rectBar.top -= nOffset;
}
else
{
bLeftBar ? rectBar.right += nOffset : rectBar.left += nOffset;
}
pBar->MoveControlBar (rectBar, FALSE, hdwp);
}
else if (pContainer != NULL)
{
// the container will be stretched by "foregn" slider, threfore
// if the native bar's slider is horizontal, a container
// will be stretched vertically
pContainer->StretchContainer (nOffset, bHorz, bLeftBar, TRUE, hdwp);
}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::Move (CPoint ptNewLeftTop)
{
ASSERT_VALID (this);
CRect rectLeft; rectLeft.SetRectEmpty ();
CRect rectRight; rectRight.SetRectEmpty ();
int nLeftOffset = 0;
int nTopOffset = 0;
if (m_pBarLeftTop != NULL)
{
m_pBarLeftTop->GetWindowRect (rectLeft);
m_pBarLeftTop->SetWindowPos (NULL, ptNewLeftTop.x, ptNewLeftTop.y, 0, 0,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
if (m_pLeftContainer != NULL)
{
m_pLeftContainer->GetWindowRect (rectLeft);
m_pLeftContainer->Move (ptNewLeftTop);
}
nLeftOffset = rectLeft.Width ();
nTopOffset = rectLeft.Height ();
if (m_pSlider != NULL)
{
if (m_pSlider->IsHorizontal ())
{
m_pSlider->SetWindowPos (NULL, ptNewLeftTop.x, ptNewLeftTop.y + nTopOffset,
0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
nTopOffset += m_pSlider->GetWidth ();
nLeftOffset = 0;
}
else
{
m_pSlider->SetWindowPos (NULL, ptNewLeftTop.x + nLeftOffset, ptNewLeftTop.y,
0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
nLeftOffset += m_pSlider->GetWidth ();
nTopOffset = 0;
}
}
if (m_pBarRightBottom != NULL)
{
m_pBarRightBottom->SetWindowPos (NULL, ptNewLeftTop.x + nLeftOffset,
ptNewLeftTop.y + nTopOffset,
0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
if (m_pRightContainer != NULL)
{
CPoint pt (ptNewLeftTop.x + nLeftOffset, ptNewLeftTop.y + nTopOffset);
m_pRightContainer->Move (pt);
}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::MoveWnd (CWnd* pWnd, int nOffset, BOOL bHorz)
{
ASSERT_VALID (this);
if (pWnd != NULL)
{
CWnd* pParent = pWnd->GetParent ();
ASSERT_VALID (pParent);
CRect rectWnd;
CRect rectParent;
pParent->GetClientRect (rectParent);
pWnd->GetWindowRect (rectWnd);
pParent->ScreenToClient (rectWnd);
int nActualOffset = bHorz ? rectWnd.left - rectParent.left :
rectWnd.top - rectParent.top;
bHorz ? rectWnd.OffsetRect (CPoint (nOffset - nActualOffset, 0)) : rectWnd.OffsetRect (CPoint (0, nOffset - nActualOffset));
pWnd->MoveWindow (rectWnd, TRUE);
}
}
//-----------------------------------------------------------------------------------//
int CBCGPBarContainer::CalcAvailableBarSpace (int nRequiredOffset,
CBCGPControlBar* pBar,
CBCGPBarContainer* pContainer,
BOOL bLeftBar)
{
ASSERT_VALID (this);
CRect rectBar;
int nAvailableSpace = nRequiredOffset;
if (pBar != NULL)
{
ASSERT_VALID (pBar);
pBar->GetWindowRect (rectBar);
if (IsSliderHorz ())
{
bLeftBar ? rectBar.bottom += nRequiredOffset :
rectBar.top += nRequiredOffset;
nAvailableSpace = pBar->CalcAvailableSize (rectBar).cy;
}
else
{
bLeftBar ? rectBar.right += nRequiredOffset :
rectBar.left += nRequiredOffset;
nAvailableSpace = pBar->CalcAvailableSize (rectBar).cx;
}
}
else if (pContainer != NULL)
{
ASSERT_VALID (pContainer);
nAvailableSpace = IsSliderHorz () ?
pContainer->CalcAvailableSpace (CSize (0, nRequiredOffset), bLeftBar).cy :
pContainer->CalcAvailableSpace (CSize (nRequiredOffset, 0), bLeftBar).cx;
}
return nAvailableSpace;
}
//-----------------------------------------------------------------------------------//
CSize CBCGPBarContainer::CalcAvailableSpace (CSize sizeStretch, BOOL bLeftBar)
{
ASSERT_VALID (this);
CRect rectWndOrg;
GetWindowRect (rectWndOrg);
CRect rectWndNew = rectWndOrg;
if (bLeftBar)
{
rectWndNew.right += sizeStretch.cx;
rectWndNew.bottom += sizeStretch.cy;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -