📄 bcgpbarcontainermanager.cpp
字号:
rectSlider.left = rectOriginal.right;
rectSlider.right = rectInserted.left;
break;
}
}
//-----------------------------------------------------------------------------------//
BOOL CBCGPBarContainerManager::AddControlBarAndContainer (CBCGPDockingControlBar* pBarOriginal,
CBCGPBarContainer* pContainerToInsert,
DWORD dwAlignment)
{
ASSERT_VALID (this);
ASSERT_VALID (pBarOriginal);
ASSERT_VALID (pContainerToInsert);
ASSERT (dwAlignment & CBRS_ALIGN_ANY);
if (m_pRootContainer == NULL)
{
TRACE0 ("The root container must be created first (call Create) \r\n");
return FALSE;
}
CRect rectBarOriginal;
CRect rectContainerToInsert;
CRect rectSlider; rectSlider.SetRectEmpty ();
CSize sizeMinOriginal;
pBarOriginal->GetMinSize (sizeMinOriginal);
CSize sizeMinToInsert;
pContainerToInsert->GetMinSize (sizeMinToInsert);
pBarOriginal->GetWindowRect (rectBarOriginal);
pContainerToInsert->GetWindowRect (rectContainerToInsert);
DWORD dwSliderStyle = CBCGPSlider::SS_HORZ;
CalcRects (rectBarOriginal, rectContainerToInsert, rectSlider, dwSliderStyle,
dwAlignment, sizeMinOriginal, sizeMinToInsert);
m_pDockSite->ScreenToClient (rectBarOriginal);
pBarOriginal->MoveWindow (rectBarOriginal);
m_pDockSite->ScreenToClient (rectContainerToInsert);
HDWP hdwp = NULL;
pContainerToInsert->ResizeContainer (rectContainerToInsert, hdwp);
pContainerToInsert->Move (rectContainerToInsert.TopLeft ());
// it's not a default slider
m_pDockSite->ScreenToClient (rectSlider);
CBCGPSlider* pSlider = CreateSlider (rectSlider, dwSliderStyle);
if (pSlider == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPBarContainer* pContainer = NULL;
if (m_pContainerRTC == NULL)
{
pContainer = new CBCGPBarContainer ();
}
else
{
pContainer = (CBCGPBarContainer*) m_pContainerRTC->CreateObject ();
}
pContainer->SetContainerManager (this);
pContainer->SetSlider (pSlider);
BOOL bRightNode = (dwAlignment & CBRS_ALIGN_BOTTOM) || (dwAlignment & CBRS_ALIGN_RIGHT);
pContainer->SetBar (pBarOriginal, bRightNode);
pContainer->SetContainer (pContainerToInsert, !bRightNode);
pSlider->BringWindowToTop ();
return m_pRootContainer->AddSubContainer (pContainer, bRightNode);
}
//-----------------------------------------------------------------------------------//
BOOL CBCGPBarContainerManager::AddControlBarAndSlider (CBCGPDockingControlBar* pBarOriginal,
CBCGPDockingControlBar* pBarToInsert,
POSITION posNearestBar,
DWORD dwAlignment)
{
ASSERT_VALID (this);
ASSERT_VALID (pBarOriginal);
ASSERT_VALID (pBarToInsert);
ASSERT_VALID (m_pRootContainer);
ASSERT_KINDOF (CBCGPDockingControlBar, pBarOriginal);
ASSERT_KINDOF (CBCGPDockingControlBar, pBarToInsert);
ASSERT (dwAlignment & CBRS_ALIGN_ANY);
if (m_pRootContainer == NULL)
{
TRACE0 ("The root container must be created first (call Create) \r\n");
return FALSE;
}
// insert the new bar into the list of control bars accordig to its
// hit test (side) relatively to the nearest bar
switch (dwAlignment & CBRS_ALIGN_ANY)
{
case CBRS_ALIGN_TOP:
case CBRS_ALIGN_LEFT:
m_lstControlBars.InsertBefore (posNearestBar, pBarToInsert);
break;
case CBRS_ALIGN_BOTTOM:
case CBRS_ALIGN_RIGHT:
m_lstControlBars.InsertAfter (posNearestBar, pBarToInsert);
break;
default:
ASSERT (FALSE);
return FALSE;
}
CRect rectBarOriginal;
CRect rectBarToInsert;
CRect rectSlider;
CSize sizeMinOriginal;
pBarOriginal->GetMinSize (sizeMinOriginal);
CSize sizeMinToInsert;
pBarToInsert->GetMinSize (sizeMinToInsert);
pBarOriginal->GetWindowRect (rectBarOriginal);
pBarToInsert->GetWindowRect (rectBarToInsert);
if (rectBarToInsert.Width () < sizeMinToInsert.cx)
{
rectBarToInsert.right = rectBarToInsert.left + sizeMinToInsert.cx;
}
if (rectBarToInsert.Height () < sizeMinToInsert.cy)
{
rectBarToInsert.bottom = rectBarToInsert.top + sizeMinToInsert.cy;
}
// calculate the width/height (size) of both rectangles, slider's boundaries and orientation
DWORD dwSliderStyle = 0;
int nNewSize = 0;
if (dwAlignment & CBRS_ORIENT_HORZ)
{
// align the rectangle of the bar to insert by the width of the sell
rectSlider.left = rectBarToInsert.left = rectBarOriginal.left;
rectSlider.right = rectBarToInsert.right = rectBarOriginal.right;
if (rectBarToInsert.Height () > rectBarOriginal.Height () / 2) //- sizeMinOriginal.cy * 2- CBCGPSlider::GetDefaultWidth ())
{
nNewSize = rectBarOriginal.Height () / 2; // - sizeMinOriginal.cy * 4 - CBCGPSlider::GetDefaultWidth ();
}
else
{
nNewSize = rectBarToInsert.Height ();
}
dwSliderStyle = CBCGPSlider::SS_HORZ;
}
else
{
// align the rectangle of the bar to insert by the height of the sell
rectSlider.top = rectBarToInsert.top = rectBarOriginal.top;
rectSlider.bottom = rectBarToInsert.bottom = rectBarOriginal.bottom;
if (rectBarToInsert.Width () > rectBarOriginal.Width () / 2) //- sizeMinOriginal.cx * 2 - CBCGPSlider::GetDefaultWidth ())
{
nNewSize = rectBarOriginal.Width () / 2; //- sizeMinOriginal.cx * 4;
}
else
{
nNewSize = rectBarToInsert.Width ();
}
dwSliderStyle = CBCGPSlider::SS_VERT;
}
BOOL bRightNode = FALSE;
CBCGPDockingControlBar* pLeftBar = NULL;
CBCGPDockingControlBar* pRightBar = NULL;
// set rects for both rectangles and slider
switch (dwAlignment & CBRS_ALIGN_ANY)
{
case CBRS_ALIGN_TOP:
rectBarToInsert.top = rectBarOriginal.top;
rectBarToInsert.bottom = rectBarToInsert.top + nNewSize;
rectBarOriginal.top = rectBarToInsert.bottom + CBCGPSlider::GetDefaultWidth ();
rectSlider.top = rectBarToInsert.bottom;
rectSlider.bottom = rectBarOriginal.top;
pLeftBar = pBarToInsert;
pRightBar = pBarOriginal;
break;
case CBRS_ALIGN_BOTTOM:
rectBarToInsert.top = rectBarOriginal.bottom - nNewSize;
rectBarToInsert.bottom = rectBarOriginal.bottom;
rectBarOriginal.bottom = rectBarToInsert.top - CBCGPSlider::GetDefaultWidth ();
rectSlider.top = rectBarOriginal.bottom;
rectSlider.bottom = rectBarToInsert.top;
dwSliderStyle = CBCGPSlider::SS_HORZ;
pLeftBar = pBarOriginal;
pRightBar = pBarToInsert;
bRightNode = TRUE;
break;
case CBRS_ALIGN_LEFT:
rectBarToInsert.left = rectBarOriginal.left;
rectBarToInsert.right = rectBarToInsert.left + nNewSize;
rectBarOriginal.left = rectBarToInsert.right + CBCGPSlider::GetDefaultWidth ();
rectSlider.left = rectBarToInsert.right;
rectSlider.right = rectBarOriginal.left;
pLeftBar = pBarToInsert;
pRightBar = pBarOriginal;
break;
case CBRS_ALIGN_RIGHT:
rectBarToInsert.right = rectBarOriginal.right;
rectBarToInsert.left = rectBarToInsert.right - nNewSize;
rectBarOriginal.right = rectBarToInsert.left - CBCGPSlider::GetDefaultWidth ();
rectSlider.left = rectBarOriginal.right;
rectSlider.right = rectBarToInsert.left;
pLeftBar = pBarOriginal;
pRightBar = pBarToInsert;
bRightNode = TRUE;
break;
}
m_pDockSite->ScreenToClient (rectBarOriginal);
pBarOriginal->MoveWindow (rectBarOriginal);
m_pDockSite->ScreenToClient (rectBarToInsert);
pBarToInsert->MoveWindow (rectBarToInsert);
// it's not a default slider
m_pDockSite->ScreenToClient (rectSlider);
CBCGPSlider* pSlider = CreateSlider (rectSlider, dwSliderStyle);
if (pSlider == NULL)
{
ASSERT (FALSE);
return FALSE;
}
CBCGPBarContainer* pContainer = NULL;
if (m_pContainerRTC == NULL)
{
pContainer = new CBCGPBarContainer (this, pLeftBar, pRightBar, pSlider);
}
else
{
pContainer = (CBCGPBarContainer*) m_pContainerRTC->CreateObject ();
pContainer->SetContainerManager (this);
pContainer->SetBar (pLeftBar, TRUE);
pContainer->SetBar (pRightBar, FALSE);
pContainer->SetSlider (pSlider);
}
return m_pRootContainer->AddSubContainer (pContainer, bRightNode);
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::ResizeBarContainers (UINT nSide, BOOL bExpand, int nOffset,
HDWP& hdwp)
{
ASSERT_VALID (this);
if (m_pRootContainer != NULL)
{
bool bStretchHorz = (nSide == WMSZ_RIGHT || nSide == WMSZ_LEFT);
bool bLeftBar = true;
nOffset *= bExpand ? 1 : (-1);
m_pRootContainer->StretchContainer (nOffset, bStretchHorz, bLeftBar, TRUE, hdwp);
}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::ResizeBarContainers (CRect rect, HDWP& hdwp)
{
ASSERT_VALID (this);
if (m_pRootContainer != NULL)
{
m_pRootContainer->ResizeContainer (rect, hdwp);
}
}
//-----------------------------------------------------------------------------------//
BOOL CBCGPBarContainerManager::ReplaceControlBar (CBCGPDockingControlBar* pBarOld,
CBCGPDockingControlBar* pBarNew)
{
ASSERT_VALID (this);
ASSERT_VALID (pBarOld);
ASSERT_VALID (pBarNew);
ASSERT_KINDOF (CBCGPDockingControlBar, pBarOld);
ASSERT_KINDOF (CBCGPDockingControlBar, pBarNew);
POSITION pos = m_lstControlBars.Find (pBarOld);
if (pos != NULL)
{
BOOL bLeftBar = FALSE;
CBCGPBarContainer* pContainer = FindContainer (pBarOld, bLeftBar);
if (pContainer != NULL)
{
pContainer->SetBar (pBarNew, bLeftBar);
m_lstControlBars.InsertAfter (pos, pBarNew);
m_lstControlBars.RemoveAt (pos);
}
}
else
{
m_lstControlBars.AddTail (pBarNew);
}
return TRUE;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::SetResizeMode (BOOL bResize)
{
ASSERT_VALID (this);
for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
{
CBCGPDockingControlBar* pBar =
(CBCGPDockingControlBar*) m_lstControlBars.GetNext (pos);
ASSERT_VALID (pBar);
pBar->SetResizeMode (bResize);
}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainerManager::Serialize (CArchive& ar)
{
ASSERT_VALID (this);
CObject::Serialize (ar);
if (ar.IsStoring ())
{
int nSliderCount = m_lstSliders.GetCount ();
m_pRootContainer->ReleaseEmptyContainer ();
nSliderCount = m_lstSliders.GetCount ();
m_pRootContainer->Serialize (ar);
ar << m_lstControlBars.GetCount ();
for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
{
CWnd* pNextBar = (CWnd*) m_lstControlBars.GetNext (pos);
ASSERT_VALID (pNextBar);
int nBarID = pNextBar->GetDlgCtrlID ();
if (nBarID != -1)
{
ar << nBarID;
}
else
{
// this is tab control bar - identify it by its first tabbed bar
CBCGPBaseTabbedBar* pTabBar = DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, pNextBar);
ASSERT_VALID (pTabBar);
CWnd* pWnd = pTabBar->FindBarByTabNumber (0);
if (pWnd != NULL)
{
int nTabbedBarID = pWnd->GetDlgCtrlID ();
ASSERT (nTabbedBarID != -1);
ar << nBarID;
ar << nTabbedBarID;
}
}
}
}
else
{
m_pRootContainer->Serialize (ar);
// rewrite to conform with miniframe (m_pDefaultSlider is null there) !!!
CBCGPDockManager* pDockManager = NULL;
if (m_pDefaultSlider != NULL)
{
pDockManager = globalUtils.GetDockManager (m_pDefaultSlider->GetDockSite ());
}
else if (m_pDockSite->IsKindOf (RUNTIME_CLASS (CBCGPMiniFrameWnd)))
{
pDockManager = globalUtils.GetDockManager (m_pDockSite->GetParent ());
}
if (pDockManager == NULL)
{
TRACE0 ("Unexpected NULL pointer to dock manager. Serialization failed.\n");
throw new CArchiveException;
return;
}
int nCount = 0;
// load control bar id's
ar >> nCount;
int nControlBarID = 0;
for (int i = 0; i < nCount; i++)
{
ar >> nControlBarID;
// -1 means tabbed control bar, these bars are stored and loaded by containers
if (nControlBarID != -1)
{
CBCGPDockingControlBar* pBar =
DYNAMIC_DOWNCAST (CBCGPDockingControlBar,
pDockManager->FindBarByID (nControlBarID, TRUE));
if (pBar != NULL)
{
ASSERT_VALID (pBar);
m_lstControlBars.AddTail (pBar);
m_pRootContainer->SetUpByID (nControlBarID, pBar);
}
}
else
{
// load the first tabbed bar id
ar >> nControlBarID;
CBCGPDockingControlBar* pBar =
m_pRootContainer->FindTabbedBar ((UINT) nControlBarID);
if (pBar != NULL)
{
m_lstControlBars.AddTail (pBar);
}
}
}
}
}
//-----------------------------------------------------------------------------------//
CBCGPDockingControlBar* CBCGPBarContainerManager::FindTabbedBar (UINT nID)
{
ASSERT_VALID (this);
if (m_pRootContainer != NULL)
{
return m_pRootContainer->FindTabbedBar (nID);
}
return NULL;
}
//-----------------------------------------------------------------------------------//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -