📄 bcgoutlookbar.cpp
字号:
m_uiBackImageId = (UINT) -1;
SetBackImage (uiImage);
}
else
{
m_clrRegText = ::GetSysColor (COLOR_WINDOW);
Invalidate ();
}
}
//*****************************************************************************************
void CBCGOutlookBar::AdjustLocations ()
{
if (GetSafeHwnd () == NULL)
{
return;
}
ASSERT_VALID(this);
if (m_Buttons.IsEmpty ())
{
return;
}
if (m_pBtnUp == NULL)
{
// it should be first
m_pBtnUp = DYNAMIC_DOWNCAST (CBCGOutlookButton, m_Buttons.GetHead ());
ASSERT_VALID (m_pBtnUp);
m_pBtnUp->m_nScrollBtn = -1;
}
if (m_pBtnDown == NULL)
{
// it should be last.
m_pBtnDown = DYNAMIC_DOWNCAST (CBCGOutlookButton, m_Buttons.GetTail ());
ASSERT_VALID (m_pBtnDown);
m_pBtnDown->m_nScrollBtn = 1;
}
BOOL bVert = (m_dwStyle & CBRS_ORIENT_HORZ) == 0;
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);
CRect rectClient;
GetClientRect (&rectClient);
CSize sizeDefault;
if (bVert)
{
rectClient.InflateRect (-BORDER_SIZE, -2);
sizeDefault = CSize (rectClient.Width () - 2 * MARGIN_SIZE, m_csImage.cy);
}
else
{
rectClient.InflateRect (-1, -BORDER_SIZE);
sizeDefault = CSize (m_csImage.cx, rectClient.Height () - 2 * MARGIN_SIZE);
}
int iOffset = bVert ?
rectClient.top - m_iScrollOffset :
rectClient.left - m_iScrollOffset;
if (m_iFirstVisibleButton > 0)
{
m_pBtnUp->SetRect (bVert ?
CRect ( rectClient.left + 2,
rectClient.top,
rectClient.right - 1,
rectClient.top + SCROLL_BUTTON_SIZE) :
CRect ( rectClient.left,
rectClient.top + 2,
rectClient.left + SCROLL_BUTTON_SIZE,
rectClient.bottom - 1));
iOffset += SCROLL_BUTTON_SIZE;
}
else
{
m_pBtnUp->SetRect (CRect (0, 0, 0, 0));
}
int iIndex = 1;
for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL; iIndex ++)
{
CBCGOutlookButton* pButton = (CBCGOutlookButton*) m_Buttons.GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nScrollBtn != 0)
{
continue;
}
pButton->m_bTextBelow = m_bTextLabels;
CSize sizeButton = pButton->OnCalculateSize (&dc, sizeDefault, !bVert);
CRect rectButton;
if (bVert)
{
rectButton = CRect (rectClient.left + MARGIN_SIZE,
iOffset,
rectClient.right - 1,
iOffset + sizeButton.cy);
iOffset = rectButton.bottom;
}
else
{
rectButton = CRect (rectClient.left + iOffset,
rectClient.top + MARGIN_SIZE,
rectClient.left + iOffset + sizeButton.cx,
rectClient.bottom - 1);
iOffset = rectButton.right;
}
pButton->SetRect (rectButton);
}
if (bVert)
{
m_bScrollDown = (iOffset > rectClient.bottom);
}
else
{
m_bScrollDown = (iOffset > rectClient.right);
}
if (m_bScrollDown)
{
m_pBtnDown->SetRect (bVert ?
CRect ( rectClient.left + 2,
rectClient.bottom - SCROLL_BUTTON_SIZE,
rectClient.right - 1,
rectClient.bottom) :
CRect ( rectClient.right - SCROLL_BUTTON_SIZE,
rectClient.top + 2,
rectClient.right,
rectClient.bottom - 1));
}
else
{
m_pBtnDown->SetRect (CRect (0, 0, 0, 0));
}
dc.SelectObject (pOldFont);
}
//*************************************************************************************
void CBCGOutlookBar::DoPaint(CDC* pDC)
{
ASSERT_VALID(this);
ASSERT_VALID(pDC);
BOOL bHorz = m_dwStyle & CBRS_ORIENT_HORZ ? TRUE : FALSE;
CRect rectClient;
GetClientRect (rectClient);
pDC->SetTextColor (globalData.clrBtnText);
pDC->SetBkMode (TRANSPARENT);
CRect rectBorder = rectClient;
if (!bHorz)
{
rectBorder.InflateRect (0, 2);
rectBorder.left = rectBorder.right - BORDER_SIZE;
}
else
{
rectBorder.InflateRect (2, 0);
rectBorder.bottom = rectBorder.top + BORDER_SIZE;
}
pDC->FillRect (rectBorder, &globalData.brBtnFace);
pDC->Draw3dRect (rectBorder, ::GetSysColor (COLOR_3DHILIGHT),
::GetSysColor (COLOR_3DSHADOW));
CRect rectSpace = rectClient;
if (!bHorz)
{
CRect rectLeft = rectClient;
rectLeft.right = BORDER_SIZE;
pDC->FillRect (rectLeft, &globalData.brBtnFace);
rectSpace.left = rectLeft.right;
rectSpace.right = rectBorder.left;
}
else
{
CRect rectBottom = rectClient;
rectBottom.top = rectBottom.bottom - BORDER_SIZE;
pDC->FillRect (rectBottom, &globalData.brBtnFace);
rectSpace.top = rectBorder.bottom;
rectSpace.bottom = rectBottom.top;
}
pDC->Draw3dRect (rectSpace, ::GetSysColor (COLOR_3DSHADOW),
::GetSysColor (COLOR_3DHILIGHT));
if (!bHorz)
{
rectSpace.InflateRect (0, -1);
rectSpace.left ++;
}
else
{
rectSpace.InflateRect (-1, 0);
rectSpace.top ++;
}
pDC->Draw3dRect (rectSpace, ::GetSysColor (COLOR_3DDKSHADOW),
::GetSysColor (COLOR_3DLIGHT));
CBCGDrawState ds;
if (!m_Images.PrepareDrawImage (ds))
{
return; // something went wrong
}
CFont* pOldFont = pDC->SelectObject (&globalData.fontRegular);
//--------------
// Draw buttons:
//--------------
if (!bHorz)
{
rectClient.InflateRect (-BORDER_SIZE, -2);
}
else
{
rectClient.InflateRect (-1, -BORDER_SIZE);
}
CRgn rgn;
rgn.CreateRectRgnIndirect (rectClient);
pDC->SelectClipRgn (&rgn);
POSITION pos = m_Buttons.GetHeadPosition ();
int iButton = 1;
m_Buttons.GetNext (pos); // Skip "Up" button
BOOL bStop = FALSE;
for (; !bStop; iButton ++)
{
CBCGOutlookButton* pButton = NULL;
if (pos == NULL)
{
pButton = (CBCGOutlookButton*) m_Buttons.GetHead ();
iButton = 0;
bStop = TRUE;
}
else
{
pButton = (CBCGOutlookButton*) m_Buttons.GetNext (pos);
}
ASSERT_VALID (pButton);
CRect rect = pButton->Rect ();
BOOL bHighlighted = FALSE;
if (IsCustomizeMode () && !m_bLocked)
{
bHighlighted = FALSE;
}
else
{
bHighlighted = ((iButton == m_iHighlighted ||
iButton == m_iButtonCapture) &&
(m_iButtonCapture == -1 ||
iButton == m_iButtonCapture));
}
if (pDC->RectVisible(&rect))
{
pButton->OnDraw (pDC, rect, &m_Images, bHorz, IsCustomizeMode (),
bHighlighted);
}
}
//-------------------------------------------------------------
// Highlight selected button in the toolbar customization mode:
//-------------------------------------------------------------
if (m_iSelected >= m_Buttons.GetCount ())
{
m_iSelected = -1;
}
if (IsCustomizeMode () && m_iSelected >= 0 && !m_bLocked)
{
CBCGToolbarButton* pSelButton = GetButton (m_iSelected);
ASSERT (pSelButton != NULL);
if (pSelButton != NULL && pSelButton->CanBeStored ())
{
CRect rectDrag = pSelButton->Rect ();
if (pSelButton->GetHwnd () != NULL)
{
rectDrag.InflateRect (0, 1);
}
pDC->DrawDragRect (&rectDrag, CSize (2, 2), NULL, CSize (2, 2));
}
}
if (IsCustomizeMode () && m_iDragIndex >= 0 && !m_bLocked)
{
DrawDragMarker (pDC);
}
pDC->SelectClipRgn (NULL);
pDC->SelectObject (pOldFont);
m_Images.EndDrawImage (ds);
}
//****************************************************************************************
int CBCGOutlookBar::HitTest(CPoint point)
{
//-----------------------------
// First, check scroll buttons:
//-----------------------------
if (m_pBtnUp != NULL && m_pBtnUp->Rect ().PtInRect (point))
{
ASSERT ((CBCGOutlookButton*) m_Buttons.GetHead () == m_pBtnUp);
return 0;
}
if (m_pBtnDown != NULL && m_pBtnDown->Rect ().PtInRect (point))
{
ASSERT ((CBCGOutlookButton*) m_Buttons.GetTail () == m_pBtnDown);
return m_Buttons.GetCount () - 1;
}
return CBCGToolBar::HitTest (point);
}
//****************************************************************************************
BOOL CBCGOutlookBar::OnSendCommand (const CBCGToolbarButton* pButton)
{
ASSERT_VALID (pButton);
CBCGOutlookButton* pOLButton = DYNAMIC_DOWNCAST (CBCGOutlookButton, pButton);
if (pOLButton == NULL)
{
return FALSE;
}
if (pOLButton->m_nScrollBtn < 0)
{
ScrollUp ();
return TRUE;
}
if (pOLButton->m_nScrollBtn > 0)
{
ScrollDown ();
return TRUE;
}
return FALSE;
}
//****************************************************************************************
DROPEFFECT CBCGOutlookBar::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
CBCGToolbarButton* pButton = CBCGToolbarButton::CreateFromOleData (pDataObject);
if (pButton == NULL)
{
return DROPEFFECT_NONE;
}
BOOL bAllowDrop = pButton->IsKindOf (RUNTIME_CLASS (CBCGOutlookButton));
delete pButton;
if (!bAllowDrop)
{
return DROPEFFECT_NONE;
}
int iHit = HitTest (point);
if (iHit == 0)
{
ScrollUp ();
return DROPEFFECT_NONE;
}
if (iHit == m_Buttons.GetCount () - 1)
{
ScrollDown ();
return DROPEFFECT_NONE;
}
return CBCGToolBar::OnDragOver (pDataObject, dwKeyState, point);
}
//***************************************************************************************
int CBCGOutlookBar::FindDropIndex (const CPoint point, CRect& rectDrag) const
{
int iIndex = CBCGToolBar::FindDropIndex (point, rectDrag);
if (iIndex == 0 && m_pBtnUp != NULL)
{
iIndex ++;
rectDrag.OffsetRect (0, m_pBtnUp->Rect ().Height ());
}
if (iIndex == m_Buttons.GetCount () && m_pBtnDown != NULL)
{
iIndex --;
rectDrag.OffsetRect (0, -m_pBtnDown->Rect ().Height ());
}
return iIndex;
}
//***************************************************************************************
void CBCGOutlookBar::RemoveAllButtons ()
{
CBCGToolBar::RemoveAllButtons ();
m_pBtnUp = NULL;
m_pBtnDown = NULL;
}
//***************************************************************************************
BOOL CBCGOutlookBar::EnableContextMenuItems (CBCGToolbarButton* pButton, CMenu* pPopup)
{
ASSERT_VALID (pButton);
ASSERT_VALID (pPopup);
if (IsCustomizeMode ())
{
pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_IMAGE, MF_GRAYED | MF_BYCOMMAND);
pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_TEXT, MF_GRAYED | MF_BYCOMMAND);
pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_IMAGE_AND_TEXT, MF_GRAYED | MF_BYCOMMAND);
pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_APPEARANCE, MF_GRAYED | MF_BYCOMMAND);
pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_START_GROUP, MF_GRAYED | MF_BYCOMMAND);
pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_RESET, MF_GRAYED | MF_BYCOMMAND);
pPopup->EnableMenuItem (ID_BCGBARRES_COPY_IMAGE, MF_GRAYED | MF_BYCOMMAND);
}
CBCGToolBar::EnableContextMenuItems (pButton, pPopup);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -