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

📄 bcgpdockbar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		{
			return pRow;
		}
	}

	return NULL;
}
//----------------------------------------------------------------------------------//
BOOL CBCGPDockBar::ShowControlBar (CBCGPBaseControlBar* pBar, BOOL bShow, BOOL bDelay, BOOL bActivate)
{
	CBCGPDockBarRow* pRow = RowFromControlBar (pBar);

	if (pRow != NULL)
	{
		CBCGPControlBar* pBarToShow = DYNAMIC_DOWNCAST (CBCGPControlBar, pBar);
		// allows to show/hide only CBCGPControlBar-derived bars (other bars
		// has no docking abilitty)
		if (pBarToShow != NULL)
		{
			return pRow->ShowControlBar (pBarToShow, bShow, bDelay);
		}
	}
	return FALSE;
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::ResizeDockBarByOffset (int nOffset, BOOL bAdjustLayout)
{
	ASSERT_VALID (this);

	CRect rect;
	GetWindowRect (&rect);
	GetParent ()->ScreenToClient (&rect);

	switch (GetCurrentAlignment ())
	{
	case CBRS_ALIGN_LEFT:
		rect.right += nOffset;
		break;

	case CBRS_ALIGN_RIGHT:
		rect.left -= nOffset;
		break;

	case CBRS_ALIGN_TOP:
		rect.bottom += nOffset;
		break;

	case CBRS_ALIGN_BOTTOM:
		rect.top  -= nOffset;
		break;
	}

	MoveWindow (rect);
	if (bAdjustLayout)
	{
		AdjustDockingLayout ();
	}
}
//----------------------------------------------------------------------------------//
bool CBCGPDockBar::IsLastRow (CBCGPDockBarRow* pRow) const
{
	ASSERT_VALID (this);
	return (!m_lstDockBarRows.IsEmpty () && 
			(pRow == m_lstDockBarRows.GetHead () ||
			 pRow == m_lstDockBarRows.GetTail ()));
}
//----------------------------------------------------------------------------------//
CSize CBCGPDockBar::CalcFixedLayout (BOOL bStretch, BOOL bHorz)
{
	ASSERT_VALID (this);

	int nTotalHeightRequired = 0;

	BOOL bHorzBar = IsHorizontal ();

	for (POSITION pos = m_lstDockBarRows.GetHeadPosition (); pos != NULL;)
	{
		CBCGPDockBarRow* pNextRow = (CBCGPDockBarRow*) m_lstDockBarRows.GetNext (pos);
		ASSERT_VALID (pNextRow);

		if (!pNextRow->IsVisible ())
		{
			continue;
		}

		int nCurrHeight = pNextRow->GetRowHeight ();
		CSize sizeRowRequired = pNextRow->CalcFixedLayout (bStretch, bHorz); 

		int nHeightRequired =  bHorzBar ? sizeRowRequired.cy : sizeRowRequired.cx;

		if (nHeightRequired != nCurrHeight && nHeightRequired > 0)
		{
			ResizeRow (pNextRow, nHeightRequired, FALSE);
		}

		nTotalHeightRequired += nHeightRequired;
	}

	CRect rectWnd;
	GetWindowRect (rectWnd);

	return rectWnd.Size ();
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::ResizeDockBar (int nNewWidth, int nNewHeight) // not called from anywhere !!!
{
	ASSERT_VALID (this);
	CWnd* pParentWnd = GetParent ();
	ASSERT_VALID (pParentWnd);

	CRect rectDockBar;
	GetClientRect (&rectDockBar);
	MapWindowPoints (pParentWnd, &rectDockBar);

	switch (GetCurrentAlignment ())
	{
	case CBRS_ALIGN_LEFT:
		if (nNewHeight != -1)
		{
			rectDockBar.bottom = rectDockBar.top + nNewHeight;
		}
		break;

	case CBRS_ALIGN_RIGHT:
		if (nNewHeight != -1)
		{
			rectDockBar.bottom = rectDockBar.top + nNewHeight;
		}
		break;

	case CBRS_ALIGN_TOP:
		if (nNewWidth != -1)
		{
			rectDockBar.right = rectDockBar.left + nNewWidth;
		}
		break;

	case CBRS_ALIGN_BOTTOM:
		if (nNewWidth != -1)
		{
			rectDockBar.right = rectDockBar.left + nNewWidth;
		}
		break;
	}

	OnSetWindowPos (&wndBottom, rectDockBar, SWP_NOACTIVATE | SWP_NOZORDER);
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
}
//----------------------------------------------------------------------------------//
BOOL CBCGPDockBar::IsRectWithinDockBar (CRect rect, CPoint& ptDelta)
{
	ASSERT_VALID (this);
	CRect rectWnd;
	GetWindowRect (&rectWnd);

	ptDelta.x = ptDelta.y = 0;

	if (IsHorizontal ())
	{
		if (rect.left < rectWnd.left)
		{
			ptDelta.x = rectWnd.left - rect.left;
			return FALSE;
		}
		if (rect.right >  rectWnd.right)
		{
			ptDelta.x = rectWnd.right - rect.right;
			return FALSE;
		}
	}
	else
	{
		if (rect.top < rectWnd.top)
		{
			ptDelta.y = rectWnd.top - rect.top;
			return FALSE;
		}
		if (rect.bottom > rectWnd.bottom)
		{
			ptDelta.y = rect.bottom - rectWnd.bottom;
			return FALSE;
		}
	}

	return TRUE;
}
//----------------------------------------------------------------------------------//
BOOL CBCGPDockBar::CanAcceptBar (const CBCGPBaseControlBar* pBar) const
{
	ASSERT_VALID (this);
	if (pBar == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	return !IsResizable ();
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::OnSize(UINT nType, int cx, int cy) 
{
	ASSERT_VALID (this);

	CWnd::OnSize(nType, cx, cy);
}
//----------------------------------------------------------------------------------//
CBCGPControlBar* CBCGPDockBar::ControlBarFromPoint (CPoint pt)
{
	ASSERT_VALID (this);

	CRect rectBar;
	CBCGPControlBar* pBar = NULL;
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		pBar = (CBCGPControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pBar);

		pBar->GetWindowRect (rectBar);
		if (rectBar.PtInRect (pt))
		{
			return pBar;
		}
	}

	return NULL;
}
//----------------------------------------------------------------------------------//
int CBCGPDockBar::RectSideFromPoint (const CRect& rect, const CPoint& point)
{
	int nDeltaLeft = point.x - rect.left;
	int nDeltaTop = point.y - rect.top;
	int nDeltaRight = rect.right - point.x;
	int nDeltaBottom = rect.bottom - point.y;

	// use hit test definition to describe the side
	UINT nHitTestLR = (nDeltaLeft <= nDeltaRight) ? HTLEFT : HTRIGHT;
	UINT nHitTetsTB = (nDeltaTop <= nDeltaBottom) ? HTTOP : HTBOTTOM;
	
	int nHitTest = HTERROR;
	if (nHitTestLR == HTLEFT && nHitTetsTB == HTTOP)
	{
		nHitTest = (nDeltaLeft <= nDeltaTop) ? HTLEFT : HTTOP;
	}
	else if (nHitTestLR == HTRIGHT && nHitTetsTB == HTTOP)
	{
		nHitTest = (nDeltaRight <= nDeltaTop) ? HTRIGHT : HTTOP;
	}
	else if (nHitTestLR == HTLEFT && nHitTetsTB == HTBOTTOM)
	{
		nHitTest = (nDeltaLeft <= nDeltaBottom) ? HTLEFT : HTBOTTOM;
	}
	else if (nHitTestLR == HTRIGHT && nHitTetsTB == HTBOTTOM)
	{
		nHitTest = (nDeltaRight <= nDeltaBottom) ? HTRIGHT : HTBOTTOM;
	}
	else 
	{
		return HTERROR;
	}
	return nHitTest;
}
//----------------------------------------------------------------------------------//
BOOL CBCGPDockBar::ReplaceControlBar (CBCGPControlBar* pOldBar, CBCGPControlBar* pNewBar)
{
	ASSERT_VALID (this);
	POSITION pos = m_lstControlBars.Find (pOldBar);
	
	if (pos != NULL)
	{
		m_lstControlBars.InsertAfter (pos, pNewBar);
		m_lstControlBars.RemoveAt (pos);
		return TRUE;
	}

	return FALSE;
}
//----------------------------------------------------------------------------------//
BOOL CBCGPDockBar::OnSetWindowPos (const CWnd* pWndInsertAfter, 
								   const CRect& rectWnd, UINT nFlags)
{
	ASSERT_VALID (this);
	return (BOOL)SetWindowPos (pWndInsertAfter, 
						 rectWnd.left, rectWnd.top, rectWnd.Width (), rectWnd.Height (),
						 nFlags | SWP_NOACTIVATE);
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::OnNcDestroy() 
{
	CWnd::OnNcDestroy();
	delete this;
}
//----------------------------------------------------------------------------------//
BOOL CBCGPDockBar::OnEraseBkgnd(CDC* pDC) 
{
	CRect rect;
	GetClientRect (rect);

	CBCGPVisualManager::GetInstance ()->OnFillBarBackground (pDC, this, rect, rect, FALSE);
	return TRUE;
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::AdjustLayout ()
{
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPBaseControlBar* pBar = (CBCGPBaseControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pBar);
		pBar->AdjustLayout ();
	}
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::AdjustDockingLayout ()
{
	ASSERT_VALID (this);

	CWnd* pParent = GetParent ();
	ASSERT_VALID (pParent);

	if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
	{
		((CBCGPFrameWnd*) pParent)->AdjustDockingLayout ();
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
	{
		((CBCGPMDIFrameWnd*) pParent)->AdjustDockingLayout (NULL);
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
	{
		((CBCGPOleIPFrameWnd*) pParent)->AdjustDockingLayout ();
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
	{
		((CBCGPOleDocIPFrameWnd*) pParent)->AdjustDockingLayout ();
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
	{
		((CBCGPOleCntrFrameWnd*) pParent)->AdjustDockingLayout ();
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
	{
		((CBCGPMDIChildWnd*) pParent)->AdjustDockingLayout ();
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CDialog)))
	{
		globalUtils.m_bDialogApp = TRUE;
	}
}
//----------------------------------------------------------------------------------//
int CBCGPDockBar::FindRowIndex (CBCGPDockBarRow* pRow)
{
	ASSERT_VALID (this);

	if (pRow == NULL)
	{
		return 0;
	}

	int nIndex = 0;
	for (POSITION pos = m_lstDockBarRows.GetHeadPosition (); pos != NULL; nIndex++)
	{
		CBCGPDockBarRow* pNextRow = (CBCGPDockBarRow*) m_lstDockBarRows.GetNext (pos);
		if (pNextRow == pRow)
		{
			return nIndex;
		}
	}

	return 0;
}
//----------------------------------------------------------------------------------//
void CBCGPDockBar::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	if (!CBCGPToolBar::IsCustomizeMode () && !IsDragMode ())
	{
		CFrameWnd* pParentFrame = BCGCBProGetTopLevelFrame (this);
		if (pParentFrame == NULL)
		{
			ASSERT (FALSE);
			return;
		}

		ASSERT_VALID(pParentFrame);

		pParentFrame->SendMessage (BCGM_TOOLBARMENU,
			(WPARAM) NULL,
			MAKELPARAM(point.x, point.y));
	}
}
//----------------------------------------------------------------------------------//
BOOL CBCGPDockBar::IsDragMode () const
{
	ASSERT_VALID (this);
	
	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPControlBar* pBar = DYNAMIC_DOWNCAST 
			(CBCGPControlBar, m_lstControlBars.GetNext (pos));
		if (pBar == NULL)
		{
			continue;
		}

		if (pBar->IsDragMode ())
		{
			return TRUE;
		}
	}

	return FALSE;
}
//----------------------------------------------------------------------------------//
CBCGPControlBar* CBCGPDockBar::FindBarByID (UINT nID)
{
	ASSERT_VALID (this);

	for (POSITION pos = m_lstControlBars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPControlBar* pBar = (CBCGPControlBar*) m_lstControlBars.GetNext (pos);
		ASSERT_VALID (pBar);

		if (pBar->GetDlgCtrlID () == (int) nID)
		{
			return pBar;
		}

		//-----------------
		// Check for rebar:
		//-----------------
		CBCGPReBar* pRebar = DYNAMIC_DOWNCAST (CBCGPReBar, pBar);
		if (pRebar != NULL)
		{
			ASSERT_VALID(pRebar);

			CBCGPControlBar* pBarPane = DYNAMIC_DOWNCAST(CBCGPControlBar,
					pRebar->GetDlgItem (nID));
			if (pBarPane != NULL)
			{
				return pBarPane;
			}
		}
	}

	return NULL;
}

void CBCGPDockBar::OnDestroy() 
{
	RemoveControlBarFromDockManager (this, FALSE);
	CBCGPBaseControlBar::OnDestroy();
}

⌨️ 快捷键说明

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