⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgpbarcontainer.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		{
			m_pBarLeftTop->GetWindowRect (rectSecondBar);
		} 
		else if (m_pLeftContainer != NULL)
		{
			m_pLeftContainer->GetWindowRect (rectSecondBar);
		}

		pDockSite->ScreenToClient (rectSecondBar);

		if (m_pSlider != NULL)
		{
			if (IsSliderHorz ())
			{
				rectSlider.bottom = rectNew.top;
				rectSlider.top = rectSlider.bottom - m_pSlider->GetWidth ();
				rectSecondBar.bottom = rectSlider.top;
			}
			else
			{
				rectSlider.right = rectNew.left;
				rectSlider.left = rectSlider.right - m_pSlider->GetWidth ();
				rectSecondBar.right = rectSlider.left;
			}
		}

		if (m_pBarLeftTop != NULL)
		{
			hdwp = m_pBarLeftTop->MoveWindow (rectSecondBar, FALSE, hdwp);
		}
		else if (m_pLeftContainer != NULL)
		{
			m_pLeftContainer->ResizeContainer (rectSecondBar, hdwp);
		}
	}

	if (m_pSlider != NULL)
	{
		if (bShowSlider)
		{
			hdwp = m_pSlider->MoveWindow (rectSlider, FALSE, hdwp);
		}
		else
		{
			m_pSlider->ShowWindow (SW_HIDE);
		}
	}
	
	rectContainer.UnionRect (rectNew, rectSecondBar);
	pDockSite->ClientToScreen (rectContainer);

	if (bExpandParentContainer)
	{
		// find the first parent container that has non-empty rectangly and
		// whose left/right bar/containre should be expanded

		if (pNextContainer != NULL)
		{
			const CBCGPSlider* pParentSlider = pNextContainer->GetSlider ();

			if (pParentSlider != NULL)
			{
				ASSERT_VALID (pParentSlider);

				CBCGPBarContainer* pLeftContainer = (CBCGPBarContainer*) pNextContainer->GetLeftContainer ();
				CBCGPBarContainer* pRightContainer = (CBCGPBarContainer*) pNextContainer->GetRightContainer ();

				BOOL bIsLeftContainer = FALSE;

				if (pLeftContainer != NULL && 
					pLeftContainer-> FindSubContainer (this, BC_FIND_BY_CONTAINER))
				{
					bIsLeftContainer = TRUE;
				}
				else if (pRightContainer != NULL && 
						 pRightContainer-> FindSubContainer (this, BC_FIND_BY_CONTAINER))
				{
					bIsLeftContainer = FALSE;
				}
				else
				{
					return pBar;
				}
				
				pParentSlider->GetWindowRect (rectSlider);

				int nOffset = pParentSlider->GetWidth ();

				if (bIsLeftContainer)
				{
					if (pParentSlider->IsHorizontal ())
					{
						nOffset += nNewHeight;
						rectSlider.top = rectContainer.bottom;
						rectSlider.bottom = rectSlider.top + pParentSlider->GetWidth ();
					}
					else 
					{
						nOffset += nNewWidth;
						rectSlider.left = rectContainer.right;
						rectSlider.right = rectSlider.left + pParentSlider->GetWidth ();
					}
				}
				else
				{
					if (pParentSlider->IsHorizontal ())
					{
						nOffset = -(nNewHeight + pParentSlider->GetWidth ());
						rectSlider.bottom = rectContainer.top;
						rectSlider.top = rectSlider.bottom - pParentSlider->GetWidth ();
					}
					else 
					{
						nOffset = -(nNewWidth + pParentSlider->GetWidth ());;
						rectSlider.right = rectContainer.left;
						rectSlider.left = rectSlider.right - pParentSlider->GetWidth ();
					}
				}

				pDockSite->ScreenToClient (rectSlider);
				if (m_pSlider != NULL)
				{
					hdwp = m_pSlider->MoveWindow (rectSlider, FALSE, hdwp);
				}
				pNextContainer->ResizePartOfContainer (nOffset, !bIsLeftContainer, hdwp);
			}
		}
	}

	EndDeferWindowPos (hdwp);
	return pBar;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::ResizePartOfContainer (int nOffset, BOOL bLeftPart, 
											   HDWP& hdwp)
{
	ASSERT_VALID (this);

	if (m_pSlider == NULL)
	{
		return;
	}

	CRect rectPart; rectPart.SetRectEmpty ();
	CSize sizeMin (0, 0);

	if (bLeftPart && m_pLeftContainer != NULL)
	{
		m_pLeftContainer->GetWindowRect (rectPart);
		m_pLeftContainer->GetMinSize (sizeMin);
	}
	else if (bLeftPart && m_pBarLeftTop != NULL)
	{
		m_pBarLeftTop->GetWindowRect (rectPart);
		m_pBarLeftTop->GetMinSize (sizeMin);
	}
	else if (!bLeftPart && m_pRightContainer != NULL)
	{
		m_pRightContainer->GetWindowRect (rectPart);
		m_pRightContainer->GetMinSize (sizeMin);
	}
	else if (!bLeftPart && m_pBarRightBottom != NULL)
	{
		m_pBarRightBottom->GetWindowRect (rectPart);
		m_pBarRightBottom->GetMinSize (sizeMin);
	}
	else
	{
		return;
	}

	if (bLeftPart && IsSliderHorz ())
	{
		rectPart.bottom += nOffset;
		if (rectPart.Height () < sizeMin.cy)
		{
			rectPart.bottom = rectPart.top + sizeMin.cy;
		}
	}
	else if (bLeftPart && !IsSliderHorz ())
	{
		rectPart.right += nOffset;
		if (rectPart.Width () < sizeMin.cx)
		{
			rectPart.right = rectPart.left + sizeMin.cx;
		}
	}
	else if (!bLeftPart && IsSliderHorz ())
	{
		rectPart.top += nOffset;
		if (rectPart.Height () < sizeMin.cy)
		{
			rectPart.top = rectPart.bottom - sizeMin.cy;
		}
	}
	else
	{
		rectPart.left += nOffset;
		if (rectPart.Width () < sizeMin.cx)
		{
			rectPart.left = rectPart.right - sizeMin.cx;
		}
	}

	CWnd* pDockSite = m_pContainerManager->GetDockSite ();
	ASSERT_VALID (pDockSite);
	pDockSite->ScreenToClient (rectPart);

	if (bLeftPart && m_pLeftContainer != NULL)
	{
		m_pLeftContainer->ResizeContainer (rectPart, hdwp);
	}
	else if (bLeftPart && m_pBarLeftTop != NULL)
	{
		hdwp = m_pBarLeftTop->MoveWindow (rectPart, FALSE, hdwp);
	}
	else if (!bLeftPart && m_pRightContainer != NULL)
	{
		m_pRightContainer->ResizeContainer (rectPart, hdwp);
	}
	else if (!bLeftPart && m_pBarRightBottom != NULL)
	{
		hdwp = m_pBarRightBottom->MoveWindow (rectPart, FALSE, hdwp);
	}
}
//-----------------------------------------------------------------------------------//
BOOL CBCGPBarContainer::AddSubContainer (CBCGPBarContainer* pContainer, BOOL bRightNodeNew)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pContainer);

	// slider must be unique
	ASSERT (m_pSlider != pContainer->GetSlider ());
	
	ASSERT (pContainer->GetLeftBar () != NULL || pContainer->GetRightBar () != NULL);

	CBCGPBarContainer* pExistingContainer = NULL;
	// one of the nodes (control bars) is always new, e.g is being docked.
	// find a container that contains a node with an exisisting control bar
	// the incoming control bar is being docked to.
	const CBCGPControlBar* pBarToFind = bRightNodeNew ? pContainer->GetLeftBar () : pContainer->GetRightBar ();
	ASSERT_VALID (pBarToFind);	

	pExistingContainer = FindSubContainer (pBarToFind, BC_FIND_BY_LEFT_BAR);
	
	if (pExistingContainer == NULL)
	{
		pExistingContainer = FindSubContainer (pBarToFind, BC_FIND_BY_RIGHT_BAR);
	}

	// a node with the left or right bar must exist in the tree
	if (pExistingContainer == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	pExistingContainer->AddNode (pContainer);
	return TRUE;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::AddNode (CBCGPBarContainer* pContainer)
{
	ASSERT_VALID (this);
	// onr of the bars must be the same
	ASSERT (m_pBarLeftTop == pContainer->GetLeftBar () ||
			m_pBarLeftTop == pContainer->GetRightBar () ||
			m_pBarRightBottom == pContainer->GetLeftBar () ||
			m_pBarRightBottom == pContainer->GetRightBar ());

	if (m_pBarLeftTop != NULL && 
		(m_pBarLeftTop == pContainer->GetLeftBar () ||
		 m_pBarLeftTop == pContainer->GetRightBar ()))
	{
		m_pBarLeftTop = NULL;
		m_pLeftContainer = pContainer;
	}
	else 
	{
		m_pBarRightBottom = NULL;
		m_pRightContainer = pContainer;
	}

	pContainer->SetParentContainer (this);
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::RemoveControlBar (CBCGPDockingControlBar* pBar)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pBar);

	BC_FIND_CRITERIA barType = BC_FIND_BY_LEFT_BAR;
	CBCGPBarContainer* pContainer = FindSubContainer (pBar, barType);
	if (pContainer == NULL)
	{
		barType = BC_FIND_BY_RIGHT_BAR;
		pContainer = FindSubContainer (pBar, barType);
	}

	if (pContainer != NULL)
	{
		pContainer->DeleteControlBar (pBar, barType);
	}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::AddRef ()
{
	m_dwRefCount++;
}
//-----------------------------------------------------------------------------------//
DWORD CBCGPBarContainer::Release ()
{
	m_dwRefCount--;
	if (m_dwRefCount <= 0)
	{
		FreeReleasedContainer ();	
		return 0;
	}

	return m_dwRefCount;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::FreeReleasedContainer ()
{
	int nCountNode = 0;

	if (m_pBarLeftTop != NULL) 
	{
		nCountNode++;
	}
	if (m_pBarRightBottom != NULL)
	{
		nCountNode++;
	}
	if (m_pLeftContainer != NULL) 
	{
		nCountNode++;
	}
	if (m_pRightContainer != NULL)
	{
		nCountNode++;
	}

	if (nCountNode > 1)
	{
		return;
	}

	if (m_dwRefCount <= 0)
	{
		if ((m_pSlider != NULL && !m_pSlider->IsDefault () ||
			m_pSlider == NULL) && m_pParentContainer != NULL && 
			m_pParentContainer != m_pContainerManager->m_pRootContainer)
		{

			ASSERT (m_pParentContainer->GetLeftContainer () != NULL ||
					m_pParentContainer->GetRightContainer () != NULL);

			BOOL bLeft = (m_pParentContainer->GetLeftContainer () == this);

			m_pParentContainer->SetContainer (NULL, bLeft);

			if (m_pBarLeftTop != NULL)
			{
				m_pParentContainer->SetBar (m_pBarLeftTop, bLeft);
				m_pBarLeftTop = NULL;
			}
			else if (m_pBarRightBottom != NULL)
			{
				m_pParentContainer->SetBar (m_pBarRightBottom, bLeft);
				m_pBarRightBottom = NULL;
			}
			else if (m_pLeftContainer != NULL)
			{
				m_pParentContainer->SetContainer (m_pLeftContainer, bLeft);
				m_pLeftContainer = NULL;
			}
			else if (m_pRightContainer != NULL)
			{
				m_pParentContainer->SetContainer (m_pRightContainer, bLeft);
				m_pRightContainer = NULL;
			}

			if (m_pSlider != NULL)
			{
				m_pSlider->DestroyWindow ();
				m_pSlider = NULL;
			}

			delete this;
		}
		else
		{
			m_pContainerManager->NotifySlider ();
		}
	}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::ReleaseEmptyContainer ()
{
	if (m_pLeftContainer != NULL)
	{
		m_pLeftContainer->ReleaseEmptyContainer ();
	}

	if (m_pRightContainer != NULL)
	{
		m_pRightContainer->ReleaseEmptyContainer ();
	}

	if (m_pParentContainer != m_pContainerManager->m_pRootContainer)
	{
		FreeReleasedContainer ();
	}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::DeleteControlBar (CBCGPDockingControlBar* pBar, 
										  BC_FIND_CRITERIA barType)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pBar);

	//-------------- set recent dock info
	//StoreRecentDockInfo (pBar);
	//--------------

	CRect rectContainer;
	GetWindowRect (rectContainer);

	CRect rectBar;
	pBar->GetWindowRect (rectBar);

	// it's required to expand remaining container - take the width of slider first
	int nExpandOffset = 0;
	if (m_pSlider != NULL)
	{
		nExpandOffset = m_pSlider->GetWidth ();

		nExpandOffset += IsSliderHorz () ? rectBar.Height () : rectBar.Width ();
	}

	HDWP hdwp = BeginDeferWindowPos (10);

	BOOL bNeedToExpandParentContainer = FALSE;

	CBCGPSlider* pDefaultSlider = m_pContainerManager->GetDefaultSlider ();
	DWORD dwContainerAlignment = pDefaultSlider == NULL ? CBRS_ALIGN_LEFT : 
									pDefaultSlider->GetCurrentAlignment ();

	BOOL bIsLeftContainer = (dwContainerAlignment & CBRS_ALIGN_LEFT ||
							 dwContainerAlignment & CBRS_ALIGN_TOP) ||
							 (m_pParentContainer != NULL && 
							  m_pParentContainer->GetLeftContainer () == this);

	if (barType == BC_FIND_BY_LEFT_BAR && pBar == m_pBarLeftTop)
	{
		if (m_pBarRightBottom != NULL)
		{
			m_pBarRightBottom->MoveControlBar (rectContainer, FALSE, hdwp);
		}
		else if (m_pRightContainer != NULL && !m_pRightContainer->IsContainerEmpty ())
		{
			// expanding right container - in the left direction
			m_pBarLeftTop = NULL;

			if (bIsLeftContainer)
			{
				StretchContainer (-nExpandOffset, IsSliderHorz (), 
									FALSE, TRUE, hdwp);
			}
			else
			{
				StretchContainer (nExpandOffset, IsSliderHorz (), 
									FALSE, TRUE, hdwp);
			}

		}
		else if (m_pParentContainer != NULL)
		{
			bNeedToExpandParentContainer = TRUE;
		}

		
		m_pBarLeftTop = NULL;
	}
	else if (barType == BC_FIND_BY_RIGHT_BAR && pBar == m_pBarRightBottom)
	{
		if (m_pBarLeftTop)
		{
			m_pBarLeftTop->MoveControlBar (rectContainer, FALSE, hdwp);
		}
		else if (m_pLeftContainer != NULL && !m_pLeftContainer->IsContainerEmpty ())
		{
			// expanding left container - in the right direction
			m_pBarRightBottom = NULL;
			if (bIsLeftContainer)
			{
				StretchContainer (nExpandOffset, !IsSliderHorz (),
									TRUE, TRUE, hdwp);
			}
			else
			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -