📄 bcgptoolbarmenubutton.cpp
字号:
}
CPoint pointCheck (
rectCheck.left + (rectCheck.Width () - sizeImage.cx) / 2,
rectCheck.top + (rectCheck.Height () - sizeImage.cy) / 2);
int iImage = m_bIsRadio ? CMenuImages::IdRadio : CMenuImages::IdCheck;
FillInterior (pDC, rectCheck, bHighlight);
CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage,
pointCheck,
(m_nStyle & TBBS_DISABLED) ? CMenuImages::ImageGray : CMenuImages::ImageBlack);
CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
this, rectFrameBtn, CBCGPVisualManager::ButtonsIsPressed);
}
else if (bImageIsReady && bHighlight && !(m_nStyle & TBBS_CHECKED))
{
CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
this, rectFrameBtn, CBCGPVisualManager::ButtonsIsHighlighted);
}
else if (bImageIsReady && (m_nStyle & TBBS_CHECKED))
{
CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
this, rectFrameBtn, CBCGPVisualManager::ButtonsIsPressed);
}
int iSystemImageId = -1;
//-------------------------------
// Try to draw system menu icons:
//-------------------------------
if (!bImageIsReady)
{
switch (m_nID)
{
case SC_MINIMIZE:
iSystemImageId = CMenuImages::IdMinimize;
break;
case SC_RESTORE:
iSystemImageId = CMenuImages::IdRestore;
break;
case SC_CLOSE:
iSystemImageId = CMenuImages::IdClose;
break;
case SC_MAXIMIZE:
iSystemImageId = CMenuImages::IdMaximize;
break;
}
if (iSystemImageId != -1)
{
CRect rectSysImage = rectImage;
rectSysImage.DeflateRect (CBCGPVisualManager::GetInstance ()->GetMenuImageMargin (), CBCGPVisualManager::GetInstance ()->GetMenuImageMargin ());
CPoint pointSysImage (
rectSysImage.left + (rectSysImage.Width () - sizeImage.cx) / 2,
rectSysImage.top + (rectSysImage.Height () - sizeImage.cy) / 2);
FillInterior (pDC, rectFrameBtn, bHighlight);
CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iSystemImageId, pointSysImage,
bDisabled ? CMenuImages::ImageGray : CMenuImages::ImageBlack);
if (bHighlight)
{
CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
this, rectFrameBtn, CBCGPVisualManager::ButtonsIsHighlighted);
}
}
}
//-------------------------------
// Fill text area if highlighted:
//-------------------------------
CRect rectText = rect;
rectText.left = rectFrameBtn.right + CBCGPVisualManager::GetInstance ()->GetMenuImageMargin () + 2;
COLORREF clrText;
if (bHighlight)
{
CRect rectFill = rectFrameBtn;
if ((m_nStyle & (TBBS_CHECKED) || bImageIsReady) ||
iSystemImageId != -1)
{
rectFill.left = rectText.left - 1;
}
rectFill.right = rect.right - 1;
clrText = bDisabled ?
globalData.clrBtnFace :
globalData.clrTextHilite;
CBCGPVisualManager::GetInstance ()->OnHighlightMenuItem (pDC, this, rectFill, clrText);
}
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:
//-----------
COLORREF clrTextOld = pDC->GetTextColor ();
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 &&
CBCGPVisualManager::GetInstance ()->IsEmbossDisabledImage ())
{
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 && CBCGPVisualManager::GetInstance ()->IsEmbossDisabledImage ())
{
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 || m_bMenuOnly)
{
CFont* pRegFont = pDC->SelectObject (&globalData.fontMarlett);
ASSERT (pRegFont != NULL);
CRect rectTriangle = rect;
CString strTriangle (_T("4")); // Marlett's right arrow
if(m_bQuickCustomMode)
{
strTriangle = _T("6"); // Marlett's down arrow
}
pDC->DrawText (strTriangle, &rectTriangle, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
pDC->SelectObject (pRegFont);
}
if (pOldFont != NULL)
{
pDC->SelectObject (pOldFont);
}
pDC->SetTextColor (clrTextOld);
}
//****************************************************************************************
void CBCGPToolbarMenuButton::OnCancelMode ()
{
if (m_pPopupMenu != NULL && ::IsWindow (m_pPopupMenu->m_hWnd))
{
if (m_pPopupMenu->InCommand ())
{
return;
}
for (int i = 0; i < m_pPopupMenu->GetMenuItemCount (); i++)
{
CBCGPToolbarMenuButton* pSubItem = m_pPopupMenu->GetMenuItem (i);
if (pSubItem != NULL)
{
pSubItem->OnCancelMode ();
}
}
m_pPopupMenu->SaveState ();
m_pPopupMenu->m_bAutoDestroyParent = FALSE;
m_pPopupMenu->CloseMenu ();
}
m_pPopupMenu = NULL;
if (m_pWndParent != NULL && ::IsWindow (m_pWndParent->m_hWnd))
{
CRect rect = m_rect;
const int nShadowSize =
CBCGPVisualManager::GetInstance ()->GetMenuShadowDepth ();
rect.InflateRect (nShadowSize, nShadowSize);
m_pWndParent->InvalidateRect (rect);
m_pWndParent->UpdateWindow ();
}
m_bToBeClosed = FALSE;
}
//****************************************************************************************
BOOL CBCGPToolbarMenuButton::OpenPopupMenu (CWnd* pWnd)
{
if (m_pPopupMenu != NULL)
{
return FALSE;
}
if (pWnd == NULL)
{
pWnd = m_pWndParent;
}
ASSERT (pWnd != NULL);
HMENU hMenu = CreateMenu ();
if (hMenu == NULL && !IsEmptyMenuAllowed ())
{
return FALSE;
}
m_pPopupMenu = CreatePopupMenu ();
if (m_pPopupMenu == NULL)
{
::DestroyMenu (hMenu);
return FALSE;
}
if (m_pPopupMenu->GetMenuItemCount () > 0 && hMenu != NULL)
{
::DestroyMenu (hMenu);
hMenu = 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;
CBCGPPopupMenu::DROP_DIRECTION dropDir = CBCGPPopupMenu::DROP_DIRECTION_NONE;
CBCGPPopupMenuBar* pParentMenu =
DYNAMIC_DOWNCAST (CBCGPPopupMenuBar, m_pWndParent);
CBCGPMenuBar* pParentMenuBar =
DYNAMIC_DOWNCAST (CBCGPMenuBar, 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;
dropDir = CBCGPPopupMenu::DROP_DIRECTION_RIGHT;
}
else if (pParentMenuBar != NULL &&
(pParentMenuBar->IsHorizontal ()) == 0)
{
//------------------------------------------------
// Parent menu bar is docked vertical, place menu
// in the left or right side of the parent frame:
//------------------------------------------------
point = CPoint (m_rect.right, m_rect.top);
pWnd->ClientToScreen (&point);
dropDir = CBCGPPopupMenu::DROP_DIRECTION_RIGHT;
}
else
{
if(m_pPopupMenu->IsRightAlign())
{
point = CPoint (m_rect.right-2, m_rect.bottom - 1);
}
else
{
point = CPoint (m_rect.left, m_rect.bottom - 1);
}
dropDir = CBCGPPopupMenu::DROP_DIRECTION_BOTTOM;
pWnd->ClientToScreen (&point);
}
m_pPopupMenu->m_pParentBtn = this;
m_pPopupMenu->m_DropDirection = dropDir;
if (!m_pPopupMenu->Create (pWnd, point.x, point.y, hMenu))
{
m_pPopupMenu = NULL;
return FALSE;
}
if (m_pWndMessage != NULL)
{
ASSERT_VALID (m_pWndMessage);
m_pPopupMenu->SetMessageWnd (m_pWndMessage);
}
else
{
// yurig: if parent menu has a message window, the child should have the same
CBCGPPopupMenu* pCallerMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, pWnd->GetParent ());
if (pCallerMenu != NULL && pCallerMenu->GetMessageWnd() != NULL)
{
m_pPopupMenu->SetMessageWnd (pCallerMenu->GetMessageWnd ());
}
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPToolbarMenuButton diagnostics
#ifdef _DEBUG
void CBCGPToolbarMenuButton::AssertValid() const
{
CObject::AssertValid();
}
//******************************************************************************************
void CBCGPToolbarMenuButton::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;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_listCommands.GetNext (pos);
ASSERT_VALID (pButton);
pButton->Dump (dc);
dc << "\n";
}
dc << "}\n";
dc.SetDepth (dc.GetDepth () - 1);
dc << "\n";
}
#endif
//******************************************************************************************
int CBCGPToolbarMenuButton::OnDrawOnCustomizeList (
CDC* pDC, const CRect& rect, BOOL bSelected)
{
CBCGPToolbarButton::OnDrawOnCustomizeList (pDC, rect, bSelected);
if (m_nID == 0 || !m_listCommands.IsEmpty ()) // Popup menu
{
CBCGPVisualManager::GetInstance ()->OnDrawMenuArrowOnCustomizeList (
pDC, rect, bSelected);
}
return rect.Width ();
}
//*******************************************************************************************
BOOL CBCGPToolbarMenuButton::OnBeforeDrag () const
{
if (m_pPopupMenu != NULL) // Is dropped down
{
m_pPopupMenu->CollapseSubmenus ();
}
return CBCGPToolbarButton::OnBeforeDrag ();
}
//*******************************************************************************************
void CBCGPToolbarMenuButton::GetTextHorzOffsets (int& xOffsetLeft, int& xOffsetRight)
{
xOffsetLeft = CBCGPToolBar::GetMenuImageSize ().cx / 2 + TEXT_MARGIN;
xOffsetRight = CMenuImages::Size ().cx;
}
//*******************************************************************************************
void CBCGPToolbarMenuButton::SaveBarState ()
{
if (m_pWndParent == NULL)
{
return;
}
CBCGPPopupMenu* pParentMenu =
DYNAMIC_DOWNCAST (CBCGPPopupMenu, m_pWndParent->GetParent ());
if (pParentMenu == NULL)
{
return;
}
ASSERT_VALID (pParentMenu);
CBCGPPopupMenu* pTopLevelMenu = pParentMenu;
while ((pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, pParentMenu->GetParent ()))
!= NULL)
{
pTopLevelMenu = pParentMenu;
}
ASSERT_VALID (pTopLevelMenu);
pTopLevelMenu->SaveState ();
}
//*************************************************************************************************
void CBCGPToolbarMenuButton::GetImageRect (CRect& rectImage)
{
ASSERT_VALID (this);
rectImage = m_rect;
rectImage.left += CBCGPVisualManager::GetInstance ()->GetMenuImageMargin ();
rectImage.right = rectImage.left +
CBCGPToolBar::GetMenuImageSize ().cx + CBCGPVisualManager::GetInstance ()->GetMenuImageMargin ();
}
//*************************************************************************************************
void CBCGPToolbarMenuButton::SetTearOff (UINT uiBarID)
{
if (m_uiTearOffBarID == uiBarID)
{
return;
}
if (g_pTearOffMenuManager != NULL)
{
if (m_uiTearOffBarID != 0)
{
g_pTearOffMenuManager->SetInUse (m_uiTearOffBarID, FALSE);
}
if (uiBarID != 0)
{
g_pTearOffMenuManager->SetInUse (uiBarID);
}
}
m_uiTearOffBarID = uiBarID;
}
//*************************************************************************************************
void CBCGPToolbarMenuButton::SetMenuPaletteMode (BOOL bMenuPaletteMode/* = TRUE*/,
int nPaletteRows/* = 1*/)
{
ASSERT_VALID (this);
ASSERT (!IsDroppedDown ());
m_bMenuPaletteMode = bMenuPaletteMode;
m_nPaletteRows = nPaletteRows;
}
//***********************************************************************************
void CBCGPToolbarMenuButton::SetRadio ()
{
m_bIsRadio = TRUE;
if (m_pWndParent != NULL)
{
CRect rectImage;
GetImageRect (rectImage);
m_pWndParent->InvalidateRect (rectImage);
m_pWndParent->UpdateWindow ();
}
}
//*************************************************************************************
void CBCGPToolbarMenuButton::ResetImageToDefault ()
{
ASSERT_VALID (this);
CBCGPToolbarButton::ResetImageToDefault ();
for (POSITION pos = m_listCommands.GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarMenuButton* pItem = (CBCGPToolbarMenuButton*) m_listCommands.GetNext (pos);
ASSERT_VALID (pItem);
pItem->ResetImageToDefault ();
}
}
//********************************************************************************
BOOL CBCGPToolbarMenuButton::CompareWith (const CBCGPToolbarButton& other) const
{
if (m_nID != other.m_nID)
{
return FALSE;
}
const CBCGPToolbarMenuButton& otherMenuBtn = (const CBCGPToolbarMenuButton&) other;
if (m_listCommands.GetCount () != otherMenuBtn.m_listCommands.GetCount ())
{
return FALSE;
}
POSITION pos1 = otherMenuBtn.m_listCommands.GetHeadPosition ();
for (POSITION pos = m_listCommands.GetHeadPosition (); pos != NULL;)
{
ASSERT (pos1 != NULL);
CBCGPToolbarMenuButton* pItem = (CBCGPToolbarMenuButton*) m_listCommands.GetNext (pos);
ASSERT_VALID (pItem);
CBCGPToolbarMenuButton* pItem1 = (CBCGPToolbarMenuButton*) otherMenuBtn.m_listCommands.GetNext (pos1);
ASSERT_VALID (pItem1);
if (!pItem->CompareWith (*pItem1))
{
return FALSE;
}
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -