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

📄 bcgpdockbarrow.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				{
					nOffsetToMove = min (abs (nOffset), 
										 abs (rectNextControlBarVirt.top - rectNextControlBar.top));
				}
				int nSaveOffset = nOffsetToMove;
				if (IsEnoughSpaceToMove (pNextBar, !bMoveBackward, nSaveOffset))
				{
					MoveControlBar (pNextBar, nOffsetToMove, !bMoveBackward, hdwp);
				}						
			}
		}
	}
}
//**********************************************************************************************
void CBCGPDockBarRow::AdjustBarToRowArea (CBCGPControlBar* pBar, const CRect& rectRow, HDWP& hdwp)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pBar);

	CRect rectBarWnd;
	pBar->GetWindowRect (rectBarWnd);

	CPoint ptOffset (0, 0);
	if (IsHorizontal ()) 
	{
		if (rectBarWnd.left < rectRow.left)
		{
			ptOffset = CPoint (rectRow.left - rectBarWnd.left, 0);
			MoveControlBar (pBar, ptOffset, FALSE, hdwp);
		}

		if (rectBarWnd.right > rectRow.right)
		{
			ptOffset = CPoint (rectRow.right - rectBarWnd.right, 0);
			MoveControlBar (pBar, ptOffset, FALSE, hdwp);
		}
	}
	else
	{
		if (rectBarWnd.top < rectRow.top)
		{
			ptOffset = CPoint (0, rectRow.top - rectBarWnd.top);
			MoveControlBar (pBar, ptOffset, FALSE, hdwp);
		}

		if (rectBarWnd.bottom > rectRow.bottom)
		{
			ptOffset = CPoint (0, rectRow.bottom - rectBarWnd.bottom);
			MoveControlBar (pBar, ptOffset, FALSE, hdwp);
		}
	}
}
//**********************************************************************************************
BOOL CBCGPDockBarRow::ReplaceControlBar (CBCGPControlBar* pBarOld, CBCGPControlBar* pBarNew)
{
	ASSERT_VALID (this);

	POSITION pos = m_lstControlBars.Find (pBarOld);
	if (pos != NULL)
	{
		m_lstControlBars.InsertAfter (pos, pBarNew);
		m_lstControlBars.RemoveAt (pos);
		return TRUE;
	}
	return FALSE;
}
//**********************************************************************************************
BOOL CBCGPDockBarRow::IsExclusiveRow () const
{
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPControlBar* pNextBar = (CBCGPControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pNextBar);
		if (!pNextBar->DoesAllowSiblingBars ())
		{
			return TRUE;
		}
	}

	return FALSE;
}
//**********************************************************************************************
int CBCGPDockBarRow::CalcLastBarOffset ()
{
	if (m_lstControlBars.IsEmpty ())
	{
		return 0;
	}

	CBCGPControlBar* pLastBar = (CBCGPControlBar*) m_lstControlBars.GetTail ();
	ASSERT_VALID (pLastBar);

	CRect rect;
	pLastBar->GetWindowRect (rect);

	m_pParentDockBar->ScreenToClient (rect);

	return IsHorizontal () ? rect.right : rect.bottom;
}
//**********************************************************************************************
void CBCGPDockBarRow::RedrawAll ()
{
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPControlBar* pNextBar = (CBCGPControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pNextBar);
		pNextBar->RedrawWindow (NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
	}
}
//**********************************************************************************************
void CBCGPDockBarRow::GetGroupFromBar (CBCGPControlBar* pBar, CObList& lst)
{
	POSITION pos = m_lstControlBars.Find (pBar);
	if (pos == NULL)
	{
		return;
	}

	// find first control bar in group
	for (POSITION posGrp = pos; posGrp != NULL;)
	{
		CBCGPControlBar* pPrevBar = (CBCGPControlBar*) m_lstControlBars.GetPrev (posGrp);
		ASSERT_VALID (pPrevBar);
		if (pPrevBar->m_bFirstInGroup)
		{
			if (posGrp == NULL)
			{
				posGrp =m_lstControlBars.GetHeadPosition ();
			}
			else
			{
				m_lstControlBars.GetNext (posGrp);
			}
			break;
		}
	}

	// collect all bars in the group
	while (posGrp != NULL)
	{
		CBCGPControlBar* pNextBar = (CBCGPControlBar*) m_lstControlBars.GetNext (posGrp);
		ASSERT_VALID (pNextBar);
		lst.AddTail (pNextBar);

		if (pNextBar->m_bLastInGroup)
		{
			break;
		}
	}
}

//**********************************************************************************************
void CBCGPDockBarRow::BeginTrans ()
{
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPControlBar* pNextBar = (CBCGPControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pNextBar);
		if (!pNextBar->IsVisible () && !m_bIgnoreBarVisibility)
		{
			continue;
		}
		pNextBar->FillWindowRect ();
	}	 
}
//**********************************************************************************************
void CBCGPDockBarRow::CommitTrans ()
{
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPControlBar* pNextBar = (CBCGPControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pNextBar);
		if (!pNextBar->IsVisible () && !m_bIgnoreBarVisibility)
		{
			continue;
		}
		CRect rect = pNextBar->GetBarRect ();
		CRect rectWnd;
		pNextBar->GetWindowRect (rectWnd);

		if (rect == rectWnd)
		{
			continue;
		}

		pNextBar->GetParent ()->ScreenToClient (rect);
		pNextBar->SetWindowPos (NULL, rect.left, rect.top, rect.Width (), 
								rect.Height (), SWP_NOZORDER | SWP_NOACTIVATE);
	}	
}
//**********************************************************************************************
int CBCGPDockBarRow::GetAvailableLengthRect ()
{
	CRect rectRow;
	GetClientRect (rectRow);

	int nTotalBarLength = 0;
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPControlBar* pNextBar = (CBCGPControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pNextBar);
		if (!pNextBar->IsVisible () && !m_bIgnoreBarVisibility)
		{
			continue;
		}

		CRect rectWnd = pNextBar->GetBarRect ();
		nTotalBarLength += IsHorizontal () ? rectWnd.Width () : rectWnd.Height ();
	}

	// debug variable
	int nAvailableLength = IsHorizontal () ? rectRow.Width () - nTotalBarLength :
											 rectRow.Height () - nTotalBarLength;

	return nAvailableLength;
}
//**********************************************************************************************
int CBCGPDockBarRow::StretchBarRect (CBCGPControlBar* pBar, int nStretchSize)
{
	// the bar is stretched - calculate how far it can be expanded and do not
	// exceed its original size
	int nAvailExpandSize = pBar->GetAvailableExpandSize ();
	int nAvailStretchSize = pBar->GetAvailableStretchSize ();

	int nActualStretchSize = 0;
	if (nStretchSize > 0)
	{
		if (nAvailExpandSize == 0)
		{
			return 0;
		}
		// the bar is expanded 
		nActualStretchSize = nAvailExpandSize > nStretchSize ? nStretchSize : nAvailExpandSize;
	}
	else
	{
		nActualStretchSize = nAvailStretchSize < abs (nStretchSize) ? -nAvailStretchSize : nStretchSize;
	}


	CRect rect = pBar->GetBarRect ();

	if (IsHorizontal ())
	{
		rect.right += nActualStretchSize; 
	}
	else
	{
		rect.bottom += nActualStretchSize; 
	}	

	if (abs (nActualStretchSize) > 0)
	{
		pBar->SetBarRect (rect);
	}

	return nActualStretchSize;
}

//**********************************************************************************************
void CBCGPDockBarRow::ArrangeBarsRect (CBCGPControlBar* pInitialBar)
{
	ASSERT_VALID (this);
		
	if (m_lstControlBars.IsEmpty ())
	{
		return;
	}

	CRect rectRow;
	GetClientRect (rectRow);

	if (rectRow.IsRectEmpty ())
	{
		// the row still is not initialized
		return;
	}


	HDWP hdwp = NULL;
	int nAvailLength = GetAvailableLengthRect ();

	// handle single bar
	if (m_lstControlBars.GetCount () == 1)
	{
		if (pInitialBar == NULL)
		{
			pInitialBar = (CBCGPControlBar*) m_lstControlBars.GetHead ();
		}
		ASSERT_VALID (pInitialBar);

		if (nAvailLength < 0)
		{
			StretchBarRect (pInitialBar, nAvailLength);
			CRect rectBar = pInitialBar->GetBarRect ();
			pInitialBar->SetBarRect (rectBar);
			return;
		}
	}

	if (pInitialBar != NULL)
	{
		ResolveIntersectionRect (pInitialBar, false);
	}
	
	if (pInitialBar == NULL)
	{
		pInitialBar = (CBCGPControlBar*) m_lstControlBars.GetHead ();
	}

	ResolveIntersectionRect (pInitialBar, true);

	CBCGPControlBar* pFirstBar = FindFirstVisibleBar (TRUE);
	// how far the first bar is out of row bounds
	int nLeftOuterOffset = GetOutOfBoundsOffsetRect (pFirstBar, TRUE);

	if (nLeftOuterOffset > 0)
	{
		ShiftControlBarsRect (pFirstBar, nLeftOuterOffset, TRUE);
	}

	CBCGPControlBar* pLastBar = FindFirstVisibleBar (FALSE);
	int nRightOuterOffset = GetOutOfBoundsOffsetRect (pLastBar, FALSE);

	int nStretchSize = 0;
	if (nRightOuterOffset > 0 && nAvailLength > 0)
	{
		ShiftControlBarsRect (pLastBar, -nRightOuterOffset, FALSE);
	}
	else if (nRightOuterOffset > 0 && nAvailLength <= 0)
	{
		nStretchSize = nAvailLength;
		ShiftControlBarsRect (pLastBar, -(nRightOuterOffset - abs (nAvailLength)), FALSE);
	}
	else if (nRightOuterOffset < 0)
	{
		// nothing to do
	}

	if (nStretchSize < 0)
	{
		for (POSITION pos = m_lstControlBars.GetTailPosition (); pos != NULL;)
		{
			CBCGPControlBar* pPrevBar = (CBCGPControlBar*) m_lstControlBars.GetPrev (pos);
			ASSERT_VALID (pPrevBar);

			if (!pPrevBar->IsVisible () && !m_bIgnoreBarVisibility)
			{
				continue;
			}

			int nRetSize = pPrevBar->StretchBar (nStretchSize, hdwp);
			
			MoveControlBarRect (pPrevBar, abs (nStretchSize) - abs (nRetSize), false);
			
			if (nRetSize == nStretchSize)
			{
				break;				
			}
			else
			{
				nStretchSize -= nRetSize;
			}
		}
	}
}
//**********************************************************************************************
void CBCGPDockBarRow::ResolveIntersectionRect (CBCGPControlBar* pBar, bool bForward)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pBar);

	POSITION posStart = m_lstControlBars.Find (pBar);

	CRect rectBarWnd;
	rectBarWnd.SetRectEmpty ();

	CRect rectRowWnd;
	GetWindowRect (rectRowWnd);

	CRect rectIntersect;
	CRect rectMovedBar;

	for (POSITION pos = posStart; pos != NULL;)
	{
		CBCGPControlBar* pNextBar =  (CBCGPControlBar*) 
			(bForward ? m_lstControlBars.GetNext (pos) : m_lstControlBars.GetPrev (pos));

		ASSERT_VALID (pNextBar);

		if (!pNextBar->IsVisible () && !m_bIgnoreBarVisibility)
		{
			continue;
		}
		
		rectBarWnd = pNextBar->GetBarRect ();

		CBCGPControlBar* pMovedBar = NULL;
		POSITION posSave = NULL;
		for (POSITION posMoved = pos; posMoved != NULL;)
		{
			posSave = posMoved;
			pMovedBar = (CBCGPControlBar*) 
				(bForward ? m_lstControlBars.GetNext (posMoved) : m_lstControlBars.GetPrev (posMoved));

			if (pMovedBar->IsVisible () || m_bIgnoreBarVisibility)
			{
				break;
			}
		}

		if (pMovedBar == NULL)
		{
			break;
		}

		rectMovedBar = pMovedBar->GetBarRect ();
		
		if (bForward && 
			(IsHorizontal () && rectMovedBar.left > rectBarWnd.right ||
			 !IsHorizontal () && rectMovedBar.top > rectBarWnd.bottom) ||
			!bForward && 
			(IsHorizontal () && rectMovedBar.right < rectBarWnd.left ||
			 !IsHorizontal () && rectMovedBar.bottom < rectBarWnd.top))
		{
			pos = posSave;
			continue;
		}
			

		int nMoveOffset = 0;
		if (bForward) 
		{
			nMoveOffset = IsHorizontal () ? rectBarWnd.right - rectMovedBar.left  
										  : rectBarWnd.bottom - rectMovedBar.top;
		}
		else
		{
			nMoveOffset = IsHorizontal () ? rectMovedBar.right - rectBarWnd.left
										  : rectMovedBar.bottom - rectBarWnd.top;
		}

		MoveControlBarRect (pMovedBar, nMoveOffset, bForward);
		pos = posSave;
	}
}
//**********************************************************************************************
int CBCGPDockBarRow::GetOutOfBoundsOffsetRect (CBCGPControlBar* pBar, BOOL bLeftTopBound)
{
	ASSERT_VALID (this);

	CRect rectBar;
	CRect rectRow;

	if (pBar == NULL)
	{
		pBar = (CBCGPControlBar* ) 
					(bLeftTopBound ? m_lstControlBars.GetHead () : m_lstControlBars.GetTail ());
	}

	ASSERT_VALID (pBar);

	rectBar = pBar->GetBarRect ();
	GetWindowRect (rectRow);

	int nBoundOffset = 0;

	// the offset is greater than zero if the bar is out of bounds
	if (IsHorizontal ())
	{
		nBoundOffset = bLeftTopBound ?  rectRow.left - rectBar.left : 
										rectBar.right - rectRow.right;
	}
	else
	{
		nBoundOffset = bLeftTopBound ? rectRow.top - rectBar.top : 
										rectBar.bottom - rectRow.bottom;
	}

	return nBoundOffset;
}
//**********************************************************************************************
void CBCGPDockBarRow::ShiftControlBarsRect (CBCGPControlBar* pControlBar, int nOffset, 
											BOOL bForward)
{
	ASSERT_VALID (this);
	ASSERT (!m_lstControlBars.IsEmpty ());

	if (nOffset == 0)
	{
		return;
	}

	POSITION pos = NULL; 

	if (pControlBar != NULL)
	{
		pos = m_lstControlBars.Find (pControlBar);
	}
	else
	{
		pos = bForward ? m_lstControlBars.GetHeadPosition () : m_lstControlBars.GetTailPosition ();
		pControlBar = (CBCGPControlBar*) m_lstControlBars.GetAt (pos);
	}

	int nMoveOffset = nOffset;

	CRect rectBar; rectBar.SetRectEmpty ();
	

	while (pos != NULL)
	{
		CBCGPControlBar* pNextBar = (CBCGPControlBar*) (bForward ? m_lstControlBars.GetNext (pos)  
																: m_lstControlBars.GetPrev (pos));

		if (!pNextBar->IsVisible () && !m_bIgnoreBarVisibility)
		{
			continue;
		}

		ASSERT_VALID (pNextBar);
		CRect rectNextBar = pNextBar->GetBarRect ();

		if (pNextBar != pControlBar && !rectBar.IsRectEmpty ())
		{
			if (IsHorizontal ())
			{
				nMoveOffset -= bForward ? rectNextBar.left - rectBar.right 
										: rectNextBar.right - rectBar.left;
			}
			else
			{
				nMoveOffset -= bForward ? rectNextBar.top - rectBar.bottom 
										: rectNextBar.bottom - rectBar.top;
			}
		}

		if (nMoveOffset <= 0 && bForward || nMoveOffset >= 0 && !bForward)
		{
			break;
		}
		
		rectBar = rectNextBar;
		IsHorizontal () ? rectNextBar.OffsetRect (nMoveOffset, 0) : rectNextBar.OffsetRect (0, nMoveOffset);

		pNextBar->SetBarRect (rectNextBar);
	}
}
//**********************************************************************************************
void CBCGPDockBarRow::MoveControlBarRect (CBCGPControlBar* pControlBar, int nOffset, 
										  bool bForward)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pControlBar);

	if (nOffset == 0)
	{
		return;
	}

	CRect rectBarWnd = pControlBar->GetBarRect ();

	if (IsHorizontal ())
	{
		rectBarWnd.OffsetRect (bForward ? nOffset : -nOffset, 0);
	}
	else
	{
		rectBarWnd.OffsetRect (0, bForward ? nOffset : -nOffset);
	}
	
	pControlBar->SetBarRect (rectBarWnd);
}

⌨️ 快捷键说明

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