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

📄 bcgptoolbar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

			iInsertAt = m_Buttons.GetCount () - 1;
		}
		else
		{
			//-------------------------
			// Add to the toolbar tail:
			//-------------------------
			m_Buttons.AddTail (pButton);
			pButton->OnChangeParentWnd (this);

			return m_Buttons.GetCount () - 1;
		}
	}

	POSITION pos = m_Buttons.FindIndex (iInsertAt);
	ASSERT (pos != NULL);

	m_Buttons.InsertBefore (pos, pButton);
	pButton->OnChangeParentWnd (this);

	return iInsertAt;
}
//******************************************************************************************
int CBCGPToolBar::InsertSeparator (int iInsertAt)
{
	// Don't allow add a separtor first:
	if (m_Buttons.IsEmpty () || iInsertAt == 0)
	{
		return -1;
	}

	CBCGPToolbarButton* pButton = new CBCGPToolbarButton;
	ASSERT (pButton != NULL);

	pButton->m_nStyle = TBBS_SEPARATOR;

	int iNewButtonIndex = InsertButton (pButton, iInsertAt);
	if (iNewButtonIndex == -1)
	{
		delete pButton;
	}

	return iNewButtonIndex;
}
//******************************************************************************************
void CBCGPToolBar::RemoveAllButtons ()
{
	m_iButtonCapture = -1;      // nothing captured
	m_iHighlighted = -1;
	m_iSelected = -1;

	while (!m_Buttons.IsEmpty ())
	{
		CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.RemoveHead ();
		ASSERT_VALID (pButton);

		if (pButton != NULL)
		{
			pButton->OnCancelMode ();
			delete pButton;
		}
	}

	m_pCustomizeBtn = NULL;
}
//******************************************************************************************
BOOL CBCGPToolBar::RemoveButton (int iIndex)
{
	POSITION pos = m_Buttons.FindIndex (iIndex);
	if (pos == NULL)
	{
		return FALSE;
	}

	if (iIndex == m_Buttons.GetCount () - 1 && m_pCustomizeBtn != NULL)
	{
		//-------------------------------------
		// Unable to remove "Customize" button:
		//-------------------------------------
		ASSERT_VALID (m_pCustomizeBtn);
		ASSERT (m_pCustomizeBtn == m_Buttons.GetTail ());	// Should be last!
		ASSERT (FALSE);

		return FALSE;
	}

	CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetAt (pos);
	ASSERT_VALID (pButton);

	m_Buttons.RemoveAt (pos);
	pButton->OnCancelMode ();

	delete pButton;

	if (iIndex == m_iSelected)
	{
		m_iSelected = -1;
	}
	else if (iIndex < m_iSelected && m_iSelected >= 0)
	{
		m_iSelected --;
	}

	if (iIndex == m_iButtonCapture)
	{
		m_iButtonCapture = -1;
	}
	else if (iIndex < m_iButtonCapture && m_iButtonCapture >= 0)
	{
		m_iButtonCapture --;
	}

	if (iIndex == m_iHighlighted)
	{
		m_iHighlighted = -1;
		OnChangeHot (m_iHighlighted);
	}
	else if (iIndex < m_iHighlighted && m_iHighlighted >= 0)
	{
		m_iHighlighted --;
		OnChangeHot (m_iHighlighted);
	}

	//-----------------------------------------
	// If last button is separator - remove it:
	//-----------------------------------------
	pos = m_Buttons.GetTailPosition();
	if (pos != NULL && m_pCustomizeBtn == m_Buttons.GetTail ())
	{
		m_Buttons.GetPrev (pos);
	}
	while (pos != NULL)
	{
		POSITION posSave = pos;
		CBCGPToolbarButton* pLastButton = (CBCGPToolbarButton*) m_Buttons.GetPrev(pos);
		if (pos != NULL)
		{
			if (pLastButton->m_nStyle & TBBS_SEPARATOR)
			{
				m_Buttons.RemoveAt (posSave);

				delete pLastButton;

			}
			else
			{
				//----------------------
				// Regular button, stop!
				//----------------------
				break;
			}
		}
	}

	//----------------------------
	// Don't leave two separators:
	//----------------------------
	if (iIndex > 0 && iIndex < m_Buttons.GetCount ())
	{
		CBCGPToolbarButton* pPrevButton = GetButton (iIndex - 1);
		ASSERT_VALID (pPrevButton);

		CBCGPToolbarButton* pNextButton = GetButton (iIndex);
		ASSERT_VALID (pNextButton);

		if ((pPrevButton->m_nStyle & TBBS_SEPARATOR) &&
			(pNextButton->m_nStyle & TBBS_SEPARATOR))
		{
			RemoveButton (iIndex);
		}
	}

	RebuildAccelerationKeys ();

	return TRUE;
}

#ifdef AFX_CORE3_SEG
#pragma code_seg(AFX_CORE3_SEG)
#endif

/////////////////////////////////////////////////////////////////////////////
// CBCGPToolBar attribute access

int CBCGPToolBar::CommandToIndex (UINT nIDFind, int iIndexFirst/* = 0*/) const
{
	ASSERT_VALID(this);

	int i = 0;
	for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL; i ++)
	{
		CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
		ASSERT (pButton != NULL);

		if (i >= iIndexFirst && pButton->m_nID == nIDFind)
		{
			return i;
		}
	}

	return -1;
}
//*****************************************************************
UINT CBCGPToolBar::GetItemID(int nIndex) const
{
	ASSERT_VALID(this);

	CBCGPToolbarButton* pButton = GetButton (nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return 0;
	}

	return pButton->m_nID;
}
//*****************************************************************
void CBCGPToolBar::GetItemRect(int nIndex, LPRECT lpRect) const
{
	ASSERT_VALID(this);

	ASSERT(nIndex >= 0 && nIndex < m_Buttons.GetCount ());
	ASSERT(AfxIsValidAddress(lpRect, sizeof(RECT)));

	CBCGPToolbarButton* pButton = GetButton (nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		*lpRect = CRect (0, 0, 0, 0);
	}
	else
	{
		*lpRect = pButton->Rect ();
	}
}
//*****************************************************************
void CBCGPToolBar::GetInvalidateItemRect(int nIndex, LPRECT lpRect) const
{
	ASSERT_VALID(this);
	
	ASSERT(nIndex >= 0 && nIndex < m_Buttons.GetCount ());
	ASSERT(AfxIsValidAddress(lpRect, sizeof(RECT)));
	
	CBCGPToolbarButton* pButton = GetButton (nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		*lpRect = CRect (0, 0, 0, 0);
	}
	else
	{
		*lpRect = pButton->GetInvalidateRect ();
	}
}
//***************************************************************************
UINT CBCGPToolBar::GetButtonStyle(int nIndex) const
{
	CBCGPToolbarButton* pButton = GetButton (nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return 0;
	}

	return pButton->m_nStyle;
}
//*****************************************************************
int CBCGPToolBar::ButtonToIndex (const CBCGPToolbarButton* pButton) const
{
	ASSERT_VALID (this);
	ASSERT_VALID (pButton);

	int i = 0;
	for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL; i ++)
	{
		CBCGPToolbarButton* pListButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
		ASSERT (pListButton != NULL);

		if (pListButton == pButton)
		{
			return i;
		}
	}

	return -1;
}
//*****************************************************************
void CBCGPToolBar::SetButtonStyle(int nIndex, UINT nStyle)
{
	CBCGPToolbarButton* pButton = GetButton (nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	UINT nOldStyle = pButton->m_nStyle;
	if (nOldStyle != nStyle)
	{
		if (nStyle & TBBS_DISABLED)
		{
			// Disabled button shouldn't be pressed
			nStyle &= ~TBBS_PRESSED;
		}

		// update the style and invalidate
		pButton->SetStyle (nStyle);

		// invalidate the button only if both styles not "pressed"
		if (!(nOldStyle & nStyle & TBBS_PRESSED))
		{
			InvalidateButton(nIndex);
		}
	}
}
//****************************************************************
CSize CBCGPToolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
	DWORD dwMode = bStretch ? LM_STRETCH : 0;
	dwMode |= bHorz ? LM_HORZ : 0;

	return CalcLayout (dwMode);
}
//*************************************************************************************
void CBCGPToolBar::GetButtonInfo(int nIndex, UINT& nID, UINT& nStyle, int& iImage) const
{
	ASSERT_VALID(this);

	CBCGPToolbarButton* pButton = GetButton(nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);

		nID = 0;
		nStyle = 0;
		iImage = -1;

		return;
	}

	nID = pButton->m_nID;
	nStyle = pButton->m_nStyle;
	iImage = pButton->GetImage ();
}
//*************************************************************************************
void CBCGPToolBar::SetButtonInfo(int nIndex, UINT nID, UINT nStyle, int iImage)
{
	ASSERT_VALID(this);

	CBCGPToolbarButton* pButton = GetButton(nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	ASSERT_VALID (pButton);

	pButton->m_nStyle = nStyle;
	pButton->m_nID = nID;
	pButton->SetImage (iImage);

	if ((nStyle & TBBS_SEPARATOR) && iImage > 0) // iImage parameter is a button width!
	{
		AdjustLayout ();
	}

	InvalidateButton(nIndex);
}
//*************************************************************************************
BOOL CBCGPToolBar::SetButtonText(int nIndex, LPCTSTR lpszText)
{
	ASSERT_VALID(this);
	ASSERT(lpszText != NULL);

	CBCGPToolbarButton* pButton = GetButton(nIndex);
	if (pButton == NULL)
	{
		return FALSE;
	}

	pButton->m_strText = lpszText;
	return TRUE;
}
//*************************************************************************************
CString CBCGPToolBar::GetButtonText( int nIndex ) const
{
	ASSERT_VALID(this);

	CBCGPToolbarButton* pButton = GetButton(nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return _T("");
	}

	ASSERT_VALID (pButton);

	return pButton->m_strText;
}
//*************************************************************************************
void CBCGPToolBar::GetButtonText( int nIndex, CString& rString ) const
{
	ASSERT_VALID(this);

	CBCGPToolbarButton* pButton = GetButton(nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		rString.Empty ();
		return;
	}

	ASSERT_VALID (pButton);

	rString = pButton->m_strText;
}
//*************************************************************************************
void CBCGPToolBar::DoPaint(CDC* pDCPaint)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDCPaint);

	CRect rectClip;
	pDCPaint->GetClipBox (rectClip);

	BOOL bHorz = GetCurrentAlignment () & CBRS_ORIENT_HORZ ? TRUE : FALSE;

	CRect rectClient;
	GetClientRect (rectClient);

	CDC*		pDC = pDCPaint;
	BOOL		m_bMemDC = FALSE;
	CDC			dcMem;
	CBitmap		bmp;
	CBitmap*	pOldBmp = NULL;

	if (dcMem.CreateCompatibleDC (pDCPaint) &&
		bmp.CreateCompatibleBitmap (pDCPaint, rectClient.Width (),
								  rectClient.Height ()))
	{
		//-------------------------------------------------------------
		// Off-screen DC successfully created. Better paint to it then!
		//-------------------------------------------------------------
		m_bMemDC = TRUE;
		pOldBmp = dcMem.SelectObject (&bmp);
		pDC = &dcMem;

		if ((GetStyle () & TBSTYLE_TRANSPARENT) == 0)
		{
			CBCGPVisualManager::GetInstance ()->OnFillBarBackground (pDC, this,
				rectClient, rectClip);
		}
		else
		{
			m_Impl.GetBackgroundFromParent (pDC);
		}

	}

	OnFillBackground (pDC);

	pDC->SetTextColor (globalData.clrBtnText);
	pDC->SetBkMode (TRANSPARENT);

	CRect rect;
	GetClientRect(rect);

	//-----------------------------------
	// Force the full size of the button:
	//-----------------------------------
	if (bHorz)
	{
		rect.bottom = rect.top + GetRowHeight ();
	}
	else
	{
		rect.right = rect.left + GetColumnWidth ();
	}

	CBCGPToolBarImages* pImages = 
		GetImageList (m_Images, m_ImagesLocked, m_LargeImages, m_LargeImagesLocked);
	CBCGPToolBarImages* pHotImages = pImages;
	CBCGPToolBarImages* pColdImages = 
		GetImageList (m_ColdImages, m_ColdImagesLocked, m_LargeColdImages, m_LargeColdImagesLocked);
	CBCGPToolBarImages* pDisabledImages = 
		GetImageList (m_DisabledImages, m_DisabledImagesLocked, m_LargeDisabledImages, m_LargeDisabledImagesLocked);
	CBCGPToolBarImages* pMenuImages = !m_bLocked ? 
		&m_MenuImages : &m_MenuImagesLocked;

	CBCGPToolBarImages* pDisabledMenuImages = !m_bLocked ?
		&m_DisabledMenuImages : &m_DisabledMenuImagesLocked;

	BOOL bDrawImages = pImages->IsValid ();

	pHotImages->SetTransparentColor (globalData.clrBtnFace);

	BOOL bFadeInactiveImages = CBCGPVisualManager::GetInstance ()->IsFadeInactiveImage ();

	CBCGPDrawState ds;
	if (bDrawImages && 
		!pHotImages->PrepareDrawImage (ds, 
			m_bMenuMode ? m_sizeMenuImage : GetImageSize (),
			bFadeInactiveImages))
	{
		return;     // something went wrong
	}

	CFont* pOldFont;
	if (bHorz)
	{
		pOldFont = (CFont*) pDC->SelectObject (&globalData.fontRegular);
	}
	else
	{
		pOldFont = (CFont*) pDC->SelectObject (&globalData.fontVert);
	}

	if (pColdImages->GetCount () > 0)
	{
		//------------------------------------------

⌨️ 快捷键说明

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