📄 bcgtoolbarmenubutton.cpp
字号:
{
bImageIsReady = pFrame->OnDrawMenuImage (pDC, this, rectImage);
}
else // Maybe, OLE frame...
{
CBCGOleIPFrameWnd* pOleFrame =
DYNAMIC_DOWNCAST (CBCGOleIPFrameWnd, pParentFrame);
if (pOleFrame != NULL)
{
bImageIsReady = pOleFrame->OnDrawMenuImage (pDC, this, rectImage);
}
}
}
}
pDC->SelectClipRgn (NULL);
rectImage.right ++;
if (m_nStyle & TBBS_CHECKED && !bImageIsReady)
{
if (!bLightImage && bIsRarelyUsed)
{
pDC->FillRect (rectImage, &globalData.brBtnFace);
}
CRect rectCheck = rectImage;
rectCheck.DeflateRect (0, 1);
CPoint pointCheck (
rectCheck.left + (rectCheck.Width () - sizeImage.cx) / 2,
rectCheck.top + (rectCheck.Height () - sizeImage.cy) / 2);
int iImage = (m_nStyle & TBBS_DISABLED) ? CMenuImages::IdCheckDsbl : CMenuImages::IdCheck;
CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage, pointCheck);
pDC->Draw3dRect (rectFrameBtn, globalData.clrBtnShadow, globalData.clrBtnHilite);
}
else if (bImageIsReady && bHighlight && !(m_nStyle & TBBS_CHECKED))
{
pDC->Draw3dRect (rectFrameBtn, globalData.clrBtnHilite, globalData.clrBtnShadow);
}
else if (bImageIsReady && (m_nStyle & TBBS_CHECKED))
{
pDC->Draw3dRect (rectFrameBtn, globalData.clrBtnShadow, globalData.clrBtnHilite);
}
int iSystemImageId = -1;
//-------------------------------
// Try to draw system menu icons:
//-------------------------------
if (!bImageIsReady)
{
switch (m_nID)
{
case SC_MINIMIZE:
iSystemImageId = bDisabled ? CMenuImages::IdMinimizeDsbl : CMenuImages::IdMinimize;
break;
case SC_RESTORE:
iSystemImageId = bDisabled ? CMenuImages::IdRestoreDsbl : CMenuImages::IdRestore;
break;
case SC_CLOSE:
iSystemImageId = bDisabled ? CMenuImages::IdCloseDsbl : CMenuImages::IdClose;
break;
case SC_MAXIMIZE:
iSystemImageId = bDisabled ? CMenuImages::IdMaximizeDsbl : CMenuImages::IdMaximize;
break;
}
if (iSystemImageId != -1)
{
CRect rectSysImage = rectImage;
rectSysImage.DeflateRect (IMAGE_MARGIN, IMAGE_MARGIN);
CPoint pointSysImage (
rectSysImage.left + (rectSysImage.Width () - sizeImage.cx) / 2,
rectSysImage.top + (rectSysImage.Height () - sizeImage.cy) / 2);
CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iSystemImageId, pointSysImage);
if (bHighlight)
{
pDC->Draw3dRect (&rectSysImage, globalData.clrBtnHilite, globalData.clrBtnShadow);
}
}
}
//-------------------------------
// Fill text area if highlighted:
//-------------------------------
CRect rectText = rect;
rectText.left = rectFrameBtn.right + IMAGE_MARGIN;
COLORREF clrText;
if (bHighlight && !bCustomizeMode)
{
CRect rectFill = rectFrameBtn;
if ((m_nStyle & (TBBS_CHECKED) || bImageIsReady) ||
iSystemImageId != -1)
{
rectFill.left = rectText.left - 1;
}
rectFill.right = rect.right - 1;
pDC->FillRect (&rectFill, &globalData.brHilite);
clrText = bDisabled ?
globalData.clrBtnFace :
globalData.clrTextHilite;
}
else
{
clrText = bDisabled ?
globalData.clrGrayedText :
globalData.clrBtnText;
}
//-------------------------
// Find acceleration label:
//-------------------------
CString strText = m_strText;
CString strAccel;
int iTabOffset = m_strText.Find (_T('\t'));
if (iTabOffset >= 0)
{
strText = strText.Left (iTabOffset);
strAccel = m_strText.Mid (iTabOffset + 1);
}
//-----------
// Draw text:
//-----------
rectText.left += TEXT_MARGIN;
if (!m_bWholeText)
{
CString strEllipses (_T("..."));
while (strText.GetLength () > 0 &&
pDC->GetTextExtent (strText + strEllipses).cx > rectText.Width ())
{
strText = strText.Left (strText.GetLength () - 1);
}
strText += strEllipses;
}
if (bDisabled && !bHighlight)
{
pDC->SetTextColor (globalData.clrBtnHilite);
CRect rectShft = rectText;
rectShft.OffsetRect (1, 1);
pDC->DrawText (strText, &rectShft, DT_SINGLELINE | DT_VCENTER);
}
pDC->SetTextColor (clrText);
pDC->DrawText (strText, &rectText, DT_SINGLELINE | DT_VCENTER);
//------------------------
// Draw accelerator label:
//------------------------
if (!strAccel.IsEmpty ())
{
CRect rectAccel = rectText;
rectAccel.right -= TEXT_MARGIN + sizeImage.cx;
if (bDisabled && !bHighlight)
{
pDC->SetTextColor (globalData.clrBtnHilite);
CRect rectAccelShft = rectAccel;
rectAccelShft.OffsetRect (1, 1);
pDC->DrawText (strAccel, &rectAccelShft, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
}
pDC->SetTextColor (clrText);
pDC->DrawText (strAccel, &rectAccel, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
}
//--------------------------------------------
// Draw triangle image for the cascade menues:
//--------------------------------------------
if (m_nID == (UINT) -1 || m_bDrawDownArrow)
{
CRect rectTriangle = rect;
rectTriangle.left = rectTriangle.right - sizeImage.cx;
CPoint pointTriangle (
rectTriangle.left + (rectTriangle.Width () - sizeImage.cx) / 2,
rectTriangle.top + (rectTriangle.Height () - sizeImage.cy) / 2);
int iImage = (bHighlight && !bCustomizeMode) ?
(bDisabled ? CMenuImages::IdArowLeftWhiteDsbl : CMenuImages::IdArowLeftWhite) :
(bDisabled ? CMenuImages::IdArowLeftDsbl : CMenuImages::IdArowLeft);
CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage, pointTriangle);
}
if (pOldFont != NULL)
{
pDC->SelectObject (pOldFont);
}
}
//****************************************************************************************
void CBCGToolbarMenuButton::OnCancelMode ()
{
if (m_pPopupMenu != NULL && ::IsWindow (m_pPopupMenu->m_hWnd))
{
m_pPopupMenu->SaveState ();
m_pPopupMenu->m_bAutoDestroyParent = FALSE;
// m_pPopupMenu->DestroyWindow ();
m_pPopupMenu->CloseMenu ();
}
m_pPopupMenu = NULL;
if (m_pWndParent != NULL && ::IsWindow (m_pWndParent->m_hWnd))
{
m_pWndParent->InvalidateRect (m_rect);
m_pWndParent->UpdateWindow ();
}
}
//****************************************************************************************
BOOL CBCGToolbarMenuButton::OpenPopupMenu (CWnd* pWnd)
{
if (m_pPopupMenu != NULL)
{
return FALSE;
}
if (pWnd == NULL)
{
pWnd = m_pWndParent;
}
ASSERT (pWnd != NULL);
//---------------------------------------------------------------
// Define a new menu position. Place the menu in the right side
// of the current menu in the poup menu case or under the current
// item by default:
//---------------------------------------------------------------
CPoint point;
CBCGPopupMenuBar* pParentMenu =
DYNAMIC_DOWNCAST (CBCGPopupMenuBar, m_pWndParent);
CBCGMenuBar* pParentMenuBar =
DYNAMIC_DOWNCAST (CBCGMenuBar, m_pWndParent);
if (pParentMenu != NULL)
{
point = CPoint (0, m_rect.top - 2);
pWnd->ClientToScreen (&point);
CRect rectParent;
pParentMenu->GetWindowRect (rectParent);
point.x = rectParent.right + 1;
}
else if (pParentMenuBar != NULL &&
(pParentMenuBar->m_dwStyle & CBRS_ORIENT_HORZ) == 0)
{
//------------------------------------------------
// Parent menu bar is docked vertical, place menu
// in the left or right side of the parent frame:
//------------------------------------------------
point = CPoint (m_rect.right + 1, m_rect.top);
pWnd->ClientToScreen (&point);
}
else
{
point = CPoint (m_rect.left - 1, m_rect.bottom);
pWnd->ClientToScreen (&point);
}
HMENU hMenu = CreateMenu ();
if (hMenu == NULL && !IsEmptyMenuAllowed ())
{
return FALSE;
}
m_pPopupMenu = CreatePopupMenu ();
if (m_pPopupMenu == NULL)
{
return FALSE;
}
m_pPopupMenu->m_pParentBtn = this;
if (!m_pPopupMenu->Create (pWnd, point.x, point.y, hMenu))
{
m_pPopupMenu = NULL;
return FALSE;
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CBCGToolbarMenuButton diagnostics
#ifdef _DEBUG
void CBCGToolbarMenuButton::AssertValid() const
{
CObject::AssertValid();
}
//******************************************************************************************
void CBCGToolbarMenuButton::Dump(CDumpContext& dc) const
{
CObject::Dump (dc);
CString strId;
strId.Format (_T("%x"), m_nID);
dc << "[" << m_strText << " >>>>> ]";
dc.SetDepth (dc.GetDepth () + 1);
dc << "{\n";
for (POSITION pos = m_listCommands.GetHeadPosition (); pos != NULL;)
{
CBCGToolbarButton* pButton = (CBCGToolbarButton*) m_listCommands.GetNext (pos);
ASSERT_VALID (pButton);
pButton->Dump (dc);
dc << "\n";
}
dc << "}\n";
dc.SetDepth (dc.GetDepth () - 1);
dc << "\n";
}
#endif
//******************************************************************************************
int CBCGToolbarMenuButton::OnDrawOnCustomizeList (
CDC* pDC, const CRect& rect, BOOL bSelected)
{
CBCGToolbarButton::OnDrawOnCustomizeList (pDC, rect, bSelected);
if (m_nID == 0 || !m_listCommands.IsEmpty ()) // Popup menu
{
CRect rectTriangle = rect;
rectTriangle.left = rectTriangle.right - CMenuImages::Size ().cx;
CPoint pointTriangle (
rectTriangle.left + (rectTriangle.Width () - CMenuImages::Size ().cx) / 2,
rectTriangle.top + (rectTriangle.Height () - CMenuImages::Size ().cy) / 2);
int iImage = (bSelected) ? CMenuImages::IdArowLeftWhite : CMenuImages::IdArowLeft;
CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage, pointTriangle);
CRect rectLine = rect;
rectLine.right = rectTriangle.left - 1;
rectLine.left = rectLine.right - 2;
rectLine.DeflateRect (0, 2);
pDC->Draw3dRect (&rectLine, globalData.clrBtnShadow, globalData.clrBtnHilite);
}
return rect.Width ();
}
//*******************************************************************************************
BOOL CBCGToolbarMenuButton::OnBeforeDrag () const
{
if (m_pPopupMenu != NULL) // Is dropped down
{
m_pPopupMenu->CollapseSubmenus ();
}
return CBCGToolbarButton::OnBeforeDrag ();
}
//*******************************************************************************************
void CBCGToolbarMenuButton::GetTextHorzOffsets (int& xOffsetLeft, int& xOffsetRight)
{
xOffsetLeft = CBCGToolBar::GetMenuImageSize ().cx / 2 + TEXT_MARGIN;
xOffsetRight = CMenuImages::Size ().cx;
}
//*******************************************************************************************
void CBCGToolbarMenuButton::SaveBarState ()
{
if (m_pWndParent == NULL)
{
return;
}
CBCGPopupMenu* pParentMenu =
DYNAMIC_DOWNCAST (CBCGPopupMenu, m_pWndParent->GetParent ());
if (pParentMenu == NULL)
{
return;
}
ASSERT_VALID (pParentMenu);
CBCGPopupMenu* pTopLevelMenu = pParentMenu;
while ((pParentMenu = DYNAMIC_DOWNCAST (CBCGPopupMenu, pParentMenu->GetParent ()))
!= NULL)
{
pTopLevelMenu = pParentMenu;
}
ASSERT_VALID (pTopLevelMenu);
pTopLevelMenu->SaveState ();
}
//*************************************************************************************************
void CBCGToolbarMenuButton::GetImageRect (CRect& rectImage)
{
ASSERT_VALID (this);
rectImage = m_rect;
rectImage.left += IMAGE_MARGIN;
rectImage.right = rectImage.left +
CBCGToolBar::GetMenuImageSize ().cx + IMAGE_MARGIN;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -