📄 bcgoutlookbutton.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This source code is a part of BCGControlBar library.
// You may use, compile or redistribute it as part of your application
// for free. You cannot redistribute it as a part of a software development
// library without the agreement of the author. If the sources are
// distributed along with the application, you should leave the original
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
//
// Stas Levin <stas@iet.co.il>
//*******************************************************************************
// BCGOutlookButton.cpp: implementation of the CBCGOutlookButton class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "bcgcontrolbar.h"
#include "BCGOutlookButton.h"
#include "BCGOutlookBar.h"
#include "MenuImages.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CBCGOutlookButton, CBCGToolbarButton, 1)
#define BUTTON_OFFSET 10
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBCGOutlookButton::CBCGOutlookButton()
{
m_nScrollBtn = 0;
m_pWndParentBar = NULL;
}
//***************************************************************************************
CBCGOutlookButton::~CBCGOutlookButton()
{
}
//***************************************************************************************
void CBCGOutlookButton::OnDraw (CDC* pDC, const CRect& rect, CBCGToolBarImages* pImages,
BOOL bHorz, BOOL bCustomizeMode,
BOOL bHighlight,
BOOL /*bDrawBorder*/,
BOOL /*bGrayDisabledButtons*/)
{
ASSERT_VALID (this);
ASSERT_VALID (m_pWndParentBar);
CSize csOffset (0, 0);
if (bHighlight || m_nScrollBtn != 0)
{
if (!m_pWndParentBar->IsDrawShadedHighlight () || bCustomizeMode ||
m_nScrollBtn != 0)
{
pDC->FillRect (rect, &globalData.brBtnFace);
}
else
{
// Bit pattern for a monochrome brush with every // other pixel turned off
WORD Bits[8] = { 0x0055, 0x00aa, 0x0055, 0x00aa,
0x0055, 0x00aa, 0x0055, 0x00aa };
CBitmap bmBrush;
CBrush brush;
// Need a monochrome pattern bitmap
bmBrush.CreateBitmap( 8, 8, 1, 1, &Bits );
// Create the pattern brush
brush.CreatePatternBrush( &bmBrush );
CBrush *pOldBrush = pDC->SelectObject( &brush );
// Turn every other pixel to black
COLORREF clrBk = pDC->SetBkColor( RGB(255,255,255) );
COLORREF clrText = pDC->SetTextColor (::GetSysColor (COLOR_3DSHADOW));
// 0x00A000C9 is the ROP code to AND the brush with the destination
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
(DWORD)0x00A000C9); //DPa - raster code
pDC->SetBkColor( RGB(0,0,0) );
pDC->SetTextColor( GetSysColor(COLOR_HIGHLIGHT) );
// 0x00FA0089 is the ROP code to OR the brush with the destination
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
(DWORD)0x00FA0089); //DPo - raster code
// Restore the device context
pDC->SelectObject( pOldBrush );
pDC->SetBkColor( clrBk );
pDC->SetTextColor( clrText );
}
}
if (!bCustomizeMode &&
(bHighlight || (m_nStyle & TBBS_PRESSED) || m_nScrollBtn != 0))
{
pDC->SetTextColor (m_pWndParentBar->GetSelectedColor ());
if ((m_nStyle & TBBS_PRESSED) && bHighlight)
{
pDC->Draw3dRect (rect, ::GetSysColor (COLOR_3DDKSHADOW),
::GetSysColor (COLOR_3DHILIGHT));
csOffset = CSize (2, 2);
}
else
{
pDC->Draw3dRect (rect, ::GetSysColor (COLOR_3DHILIGHT),
::GetSysColor (COLOR_3DDKSHADOW));
}
}
else
{
pDC->SetTextColor (m_pWndParentBar->GetRegularColor ());
}
CRect rectText = rect;
rectText.top += BUTTON_OFFSET / 2;
if (pImages != NULL && GetImage () >= 0)
{
int x, y;
CSize csImage = pImages->GetImageSize ();
if (!bHorz)
{
int iImageHorzOffset = (rect.Width () - csImage.cx) / 2;
x = rect.left + iImageHorzOffset + csOffset.cx;
y = rect.top + BUTTON_OFFSET / 2 + csOffset.cy;
rectText.top += csImage.cy + 2;
}
else
{
int iImageVertOffset = (rect.Height () - csImage.cy) / 2;
x = rect.left + BUTTON_OFFSET / 2 + csOffset.cx;
y = rect.top + iImageVertOffset + csOffset.cy;
rectText.left += csImage.cx + 2;
CRect rect = rectText;
int iTextHeight = pDC->DrawText (m_strText, rect,
DT_CALCRECT | DT_WORDBREAK);
rectText.top = rect.top + (rect.Height () - iTextHeight) / 2;
}
pImages->Draw (pDC, x, y, GetImage (), FALSE,
(m_nStyle & TBBS_DISABLED) && !m_pWndParentBar->IsBackgroundTexture ());
// Draw grayed images for "non-backgound" only!
}
if (m_bTextBelow && !m_strText.IsEmpty ())
{
rectText.OffsetRect (csOffset);
if (m_nStyle & TBBS_DISABLED)
{
if (m_pWndParentBar->IsBackgroundTexture ())
{
pDC->SetTextColor (::GetSysColor (COLOR_GRAYTEXT));
}
else
{
pDC->SetTextColor (globalData.clrBtnFace);
}
}
else
{
pDC->SetTextColor ((m_nStyle & TBBS_PRESSED) && bHighlight ?
m_pWndParentBar->GetSelectedColor () :
m_pWndParentBar->GetRegularColor ());
}
pDC->DrawText (m_strText, rectText,
DT_WORDBREAK | DT_CENTER);
}
if (m_nScrollBtn != 0)
{
CRect rectImage (CPoint (0, 0), CMenuImages::Size ());
CPoint point (
rect.left + (rect.Width () - rectImage.Width ()) / 2,
rect.top + (rect.Height () - rectImage.Height ()) / 2);
if ((m_nStyle & TBBS_PRESSED) && bHighlight)
{
point += CPoint (1, 1);
}
CMenuImages::Draw (pDC,
!bHorz ?
m_nScrollBtn < 0 ?
CMenuImages::IdArowUp : CMenuImages::IdArowDown :
m_nScrollBtn < 0 ?
CMenuImages::IdArowLeft : CMenuImages::IdArowRight,
point);
}
}
//****************************************************************************************
SIZE CBCGOutlookButton::OnCalculateSize (CDC* pDC, const CSize& sizeDefault, BOOL bHorz)
{
ASSERT_VALID (this);
ASSERT_VALID (pDC);
CSize sizeResult = sizeDefault;
if (!bHorz)
{
CRect rectText (0, 0, sizeDefault.cx, 1);
int iTextHeight = m_bTextBelow ? pDC->DrawText (m_strText, rectText,
DT_CALCRECT | DT_WORDBREAK) : 0;
sizeResult.cy = sizeDefault.cy + iTextHeight + BUTTON_OFFSET;
}
else
{
CRect rectText (0, 0, 0, sizeDefault.cy);
int iTextHeight = 0;
if (m_bTextBelow)
{
do
{
rectText.right ++;
iTextHeight = pDC->DrawText (m_strText, rectText,
DT_CALCRECT | DT_WORDBREAK);
}
while (iTextHeight < pDC->GetTextExtent (m_strText).cy &&
rectText.Height () > sizeDefault.cy);
}
sizeResult.cx = sizeDefault.cx + rectText.Width () + BUTTON_OFFSET;
}
return sizeResult;
}
//***************************************************************************************
void CBCGOutlookButton::OnChangeParentWnd (CWnd* pWndParent)
{
m_pWndParentBar = DYNAMIC_DOWNCAST (CBCGOutlookBar, pWndParent);
ASSERT_VALID (m_pWndParentBar);
}
//***************************************************************************************
BOOL CBCGOutlookButton::CanBeDropped (CBCGToolBar* pToolbar)
{
ASSERT_VALID (pToolbar);
return pToolbar->IsKindOf (RUNTIME_CLASS (CBCGOutlookBar));
}
//***************************************************************************************
void CBCGOutlookButton::SetImage (int iImage)
{
// Don't add image to hash!
m_iImage = iImage;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -