📄 bcgpbarcontainermanager.cpp
字号:
void CBCGPBarContainerManager::StoreRecentDockInfo (CBCGPDockingControlBar* pBar)
{
ASSERT_VALID (this);
ASSERT_VALID (pBar);
BOOL bLeftBar = TRUE;
CBCGPBarContainer* pContainer = FindContainer (pBar, bLeftBar);
if (pContainer != NULL)
{
pContainer->StoreRecentDockInfo (pBar);
}
}
//-----------------------------------------------------------------------------------//
CBCGPBaseControlBar* CBCGPBarContainerManager::GetFirstBar () const
{
ASSERT_VALID (this);
if (!m_lstControlBars.IsEmpty ())
{
return (CBCGPBaseControlBar*) m_lstControlBars.GetHead ();
}
return NULL;
}
//-----------------------------------------------------------------------------------//
BOOL CBCGPBarContainerManager::RemoveControlBarFromContainer (CBCGPDockingControlBar* pControlBar)
{
ASSERT_VALID (this);
if (m_pRootContainer == NULL)
{
return FALSE;
}
BOOL bLeftBar = FALSE;
CBCGPBarContainer* pContainer = FindContainer (pControlBar, bLeftBar);
if (pContainer == NULL)
{
return FALSE;
}
pContainer->DeleteControlBar (pControlBar,
bLeftBar ? CBCGPBarContainer::BC_FIND_BY_LEFT_BAR :
CBCGPBarContainer::BC_FIND_BY_RIGHT_BAR);
m_pRootContainer->CheckSliderVisibility ();
CBCGPSlider* pSlider = (CBCGPSlider*) pContainer->GetSlider ();
if (pSlider != NULL)
{
POSITION pos = m_lstSliders.Find (pSlider);
ASSERT (pos != NULL);
pSlider->ShowWindow (SW_HIDE);
}
POSITION pos = m_lstControlBars.Find (pControlBar);
if (pos != NULL)
{
CList<HWND,HWND> lstRecentBarHandles;
for (POSITION posBar = m_lstControlBars.GetHeadPosition (); posBar != NULL;)
{
CWnd* pWnd = DYNAMIC_DOWNCAST (CWnd, m_lstControlBars.GetNext (posBar));
ASSERT_VALID (pWnd);
lstRecentBarHandles.AddTail (pWnd->GetSafeHwnd ());
}
BOOL bDockSiteIsMiniFrame =
m_pDockSite->IsKindOf (RUNTIME_CLASS (CBCGPMiniFrameWnd));
pControlBar->m_recentDockInfo.SaveListOfRecentBars (lstRecentBarHandles, !bDockSiteIsMiniFrame);
m_lstControlBars.RemoveAt (pos);
}
return TRUE;
}
//-----------------------------------------------------------------------------------//
BOOL CBCGPBarContainerManager::OnShowControlBar (CBCGPDockingControlBar* pBar, BOOL bShow)
{
if (m_pRootContainer != NULL)
{
m_pRootContainer->CheckSliderVisibility ();
}
return IsRootContainerVisible ();
}
//-----------------------------------------------------------------------------------//
int CBCGPBarContainerManager::OnSliderMove (CBCGPSlider* pSlider, UINT uFlags,
int nOffset, HDWP& hdwp)
{
ASSERT_VALID (this);
ASSERT_VALID (pSlider);
CSize sizeMinContainer;
CRect rectContainer;
m_pRootContainer->GetWindowRect (rectContainer);
m_pRootContainer->GetMinSize (sizeMinContainer);
// check whether it is the default slider
if (pSlider == m_pDefaultSlider)
{
DWORD dwSliderAlignment = pSlider->GetCurrentAlignment ();
switch (dwSliderAlignment)
{
case CBRS_ALIGN_LEFT:
rectContainer.right += nOffset;
if (rectContainer.Width () < sizeMinContainer.cx)
{
rectContainer.right = rectContainer.left + sizeMinContainer.cx;
}
break;
case CBRS_ALIGN_RIGHT:
rectContainer.left += nOffset;
if (rectContainer.Width () < sizeMinContainer.cx)
{
rectContainer.left = rectContainer.right - sizeMinContainer.cx;
}
break;
case CBRS_ALIGN_TOP:
rectContainer.bottom += nOffset;
if (rectContainer.Height () < sizeMinContainer.cy)
{
rectContainer.bottom = rectContainer.top + sizeMinContainer.cy;
}
break;
case CBRS_ALIGN_BOTTOM:
rectContainer.top += nOffset;
if (rectContainer.Height () < sizeMinContainer.cy)
{
rectContainer.top = rectContainer.bottom - sizeMinContainer.cy;
}
break;
}
m_pDockSite->ScreenToClient (rectContainer);
ResizeBarContainers (rectContainer, hdwp);
return 0;
}
CRect rectSlider;
pSlider->GetWindowRect (&rectSlider);
CBCGPBarContainer* pContainer =
m_pRootContainer->FindSubContainer (pSlider, CBCGPBarContainer::BC_FIND_BY_SLIDER);
if (pContainer != NULL)
{
return pContainer->OnMoveInternalSlider (nOffset, hdwp);
}
return 0;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::GetMinMaxOffset (CBCGPSlider* pSlider, int& nMinOffset,
int& nMaxOffset, int& nStep)
{
ASSERT_VALID (this);
ASSERT_VALID (pSlider);
ASSERT_VALID (m_pRootContainer);
nMinOffset = nMaxOffset = 0;
nStep = -1;
CRect rectContainer;
CRect rectSlider;
pSlider->GetWindowRect (rectSlider);
if (pSlider->IsDefault ())
{
CRect rectMainClientArea;
ASSERT_VALID (pSlider->GetDockSite ());
CBCGPDockManager* pDockManager =
globalUtils.GetDockManager (pSlider->GetDockSite ());
ASSERT_VALID (pDockManager);
m_pRootContainer->GetWindowRect (rectContainer);
CSize sizeMin;
m_pRootContainer->GetMinSize (sizeMin);
rectContainer.DeflateRect (sizeMin);
rectMainClientArea = pDockManager->GetClientAreaBounds ();
pSlider->GetDockSite ()->ClientToScreen (rectMainClientArea);
rectMainClientArea.DeflateRect (g_nSliderSpacingForMove, g_nSliderSpacingForMove);
DWORD dwAlignment = pSlider->GetCurrentAlignment ();
if (dwAlignment & CBRS_ALIGN_LEFT)
{
nMinOffset = rectContainer.left - rectSlider.left + 1;
nMaxOffset = rectMainClientArea.right - rectSlider.right - 1;
}
else if (dwAlignment & CBRS_ALIGN_TOP)
{
nMinOffset = rectContainer.top - rectSlider.top + 1;
nMaxOffset = rectMainClientArea.bottom - rectSlider.bottom - 1;
}
else if (dwAlignment & CBRS_ALIGN_RIGHT)
{
nMinOffset = rectMainClientArea.left - rectSlider.left + 1;
nMaxOffset = rectContainer.right - rectSlider.right - 1;
}
else if (dwAlignment & CBRS_ALIGN_BOTTOM)
{
nMinOffset = rectMainClientArea.top - rectSlider.top + 1;
nMaxOffset = rectContainer.bottom - rectSlider.bottom - 1;
}
nStep = m_pRootContainer->GetResizeStep ();
}
else
{
CBCGPBarContainer* pContainer =
m_pRootContainer->FindSubContainer (pSlider, CBCGPBarContainer::BC_FIND_BY_SLIDER);
if (pContainer == NULL)
{
return;
}
pContainer->GetWindowRect (rectContainer);
CSize sizeMinLeft;
CSize sizeMinRight;
pContainer->GetMinSizeLeft (sizeMinLeft);
pContainer->GetMinSizeRight (sizeMinRight);
if (pSlider->IsHorizontal ())
{
nMinOffset = rectContainer.top - rectSlider.top + sizeMinLeft.cy + 1;
nMaxOffset = rectContainer.bottom - rectSlider.bottom - sizeMinRight.cy - 1;
}
else
{
nMinOffset = rectContainer.left - rectSlider.left + sizeMinLeft.cx;
nMaxOffset = rectContainer.right - rectSlider.right - sizeMinRight.cx - 1;
}
nStep = pContainer->GetResizeStep ();
}
}
//-----------------------------------------------------------------------------------//
CBCGPSlider* CBCGPBarContainerManager::CreateSlider (CRect rectSlider,
DWORD dwSliderStyle,
int nSliderID)
{
ASSERT_VALID (this);
CBCGPSlider* pSlider = new CBCGPSlider;
if (nSliderID == -1)
{
nSliderID = g_nSliderID;
g_nSliderID ++;
}
if (nSliderID >= g_nSliderID)
{
g_nSliderID = nSliderID;
g_nSliderID++;
}
for (POSITION pos = m_lstSliders.GetHeadPosition (); pos != NULL;)
{
CBCGPSlider* pNextSlider = (CBCGPSlider*) m_lstSliders.GetNext (pos);
if (pNextSlider->GetDlgCtrlID () == nSliderID)
{
nSliderID = g_nSliderID;
g_nSliderID++;
}
}
if (!pSlider->CreateEx (0, dwSliderStyle, rectSlider, m_pDockSite, nSliderID, NULL))
{
TRACE0 ("CBCGPDockSiteResizableRow: Failed to create slider");
delete pSlider;
return NULL;
}
pSlider->ShowWindow (SW_SHOW);
pSlider->SetContainerManager (this);
m_lstSliders.AddTail (pSlider);
return pSlider;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::RemoveSlider (CBCGPSlider* pSlider)
{
POSITION pos = m_lstSliders.Find (pSlider);
if (pos != NULL)
{
m_lstSliders.RemoveAt (pos);
pSlider->SetContainerManager (NULL);
}
if (m_pRootContainer != NULL)
{
CBCGPBarContainer* pContainer =
m_pRootContainer->FindSubContainer (pSlider,
CBCGPBarContainer::BC_FIND_BY_SLIDER);
if (pContainer != NULL)
{
pContainer->SetSlider (NULL);
}
}
}
//-----------------------------------------------------------------------------------//
UINT CBCGPBarContainerManager::FindBar (CPoint pt, CBCGPControlBar** ppBar, POSITION& posRet)
{
return (UINT) HTERROR;
}
//-----------------------------------------------------------------------------------//
UINT CBCGPBarContainerManager::FindBar (CRect rect, CBCGPControlBar** ppBar, POSITION& posRet)
{
return (UINT) HTERROR;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::GetWindowRect (CRect& rect) const
{
ASSERT_VALID (this);
ASSERT_VALID (m_pRootContainer);
m_pRootContainer->GetWindowRect (rect);
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::GetAvailableSpace (CRect& rect) const
{
ASSERT_VALID (this);
CRect rectUnited;
rectUnited.SetRectEmpty ();
CRect rectBar;
rectBar.SetRectEmpty ();
for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
{
CWnd* pWnd = (CWnd*) m_lstControlBars.GetNext (pos);
pWnd->GetWindowRect (rectBar);
rectUnited.UnionRect (&rectUnited, &rectBar);
}
for (pos = m_lstSliders.GetHeadPosition (); pos != NULL;)
{
CWnd* pWnd = (CWnd*) m_lstSliders.GetNext (pos);
pWnd->GetWindowRect (rectBar);
rectUnited.UnionRect (&rectUnited, &rectBar);
}
GetWindowRect (rect);
rect.SubtractRect (&rect, &rectUnited);
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::CalcRects (CRect& rectOriginal,
CRect& rectInserted,
CRect& rectSlider,
DWORD& dwSliderStyle,
DWORD dwAlignment,
CSize sizeMinOriginal,
CSize sizeMinInserted)
{
if (rectInserted.Width () < sizeMinInserted.cx)
{
rectInserted.right = rectInserted.left + sizeMinInserted.cx;
}
if (rectInserted.Height () < sizeMinInserted.cy)
{
rectInserted.bottom = rectInserted.top + sizeMinInserted.cy;
}
// calculate the width/height (size) of both rectangles, slider's boundaries and orientation
int nNewSize = 0;
if (dwAlignment & CBRS_ORIENT_HORZ)
{
// align the rectangle of the bar to insert by the width of the sell
rectSlider.left = rectInserted.left = rectOriginal.left;
rectSlider.right = rectInserted.right = rectOriginal.right;
if (rectInserted.Height () > rectOriginal.Height () / 2)
{
nNewSize = rectOriginal.Height () / 2;
}
else
{
nNewSize = rectInserted.Height ();
}
dwSliderStyle = CBCGPSlider::SS_HORZ;
}
else
{
// align the rectangle of the bar to insert by the height of the sell
rectSlider.top = rectInserted.top = rectOriginal.top;
rectSlider.bottom = rectInserted.bottom = rectOriginal.bottom;
if (rectInserted.Width () > rectOriginal.Width () / 2)
{
nNewSize = rectOriginal.Width () / 2;
}
else
{
nNewSize = rectInserted.Width ();
}
dwSliderStyle = CBCGPSlider::SS_VERT;
}
// set rects for both rectangles and slider
switch (dwAlignment & CBRS_ALIGN_ANY)
{
case CBRS_ALIGN_TOP:
rectInserted.top = rectOriginal.top;
rectInserted.bottom = rectInserted.top + nNewSize;
rectOriginal.top = rectInserted.bottom + CBCGPSlider::GetDefaultWidth ();
rectSlider.top = rectInserted.bottom;
rectSlider.bottom = rectOriginal.top;
break;
case CBRS_ALIGN_BOTTOM:
rectInserted.top = rectOriginal.bottom - nNewSize;
rectInserted.bottom = rectOriginal.bottom;
rectOriginal.bottom = rectInserted.top - CBCGPSlider::GetDefaultWidth ();
rectSlider.top = rectOriginal.bottom;
rectSlider.bottom = rectInserted.top;
break;
case CBRS_ALIGN_LEFT:
rectInserted.left = rectOriginal.left;
rectInserted.right = rectInserted.left + nNewSize;
rectOriginal.left = rectInserted.right + CBCGPSlider::GetDefaultWidth ();
rectSlider.left = rectInserted.right;
rectSlider.right = rectOriginal.left;
break;
case CBRS_ALIGN_RIGHT:
rectInserted.right = rectOriginal.right;
rectInserted.left = rectInserted.right - nNewSize;
rectOriginal.right = rectInserted.left - CBCGPSlider::GetDefaultWidth ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -