📄 bcgpdropdown.cpp
字号:
//****************************************************************************************
int CBCGPDropDownFrame::OnMouseActivate(CWnd* /*pDesktopWnd*/, UINT /*nHitTest*/, UINT /*message*/)
{
return MA_NOACTIVATE;
}
//****************************************************************************************
void CBCGPDropDownFrame::RecalcLayout (BOOL /*bNotify*/)
{
#ifdef _DEBUG
if (m_pParentBtn != NULL)
{
ASSERT_VALID (m_pParentBtn);
ASSERT (m_pParentBtn->m_pPopupMenu == this);
}
#endif // _DEBUG
if (!::IsWindow (m_hWnd) ||
!::IsWindow (m_wndToolBar.m_hWnd))
{
return;
}
CBCGPToolBar* pParentBar = m_pParentBtn == NULL ? NULL :
DYNAMIC_DOWNCAST (CBCGPToolBar, m_pParentBtn->m_pWndParent);
BOOL bHorz = pParentBar->IsHorizontal ();
CSize size = m_wndToolBar.CalcSize(bHorz);
size.cx += iBorderSize * 3;
size.cy += iBorderSize * 3;
//---------------------------------------------
// Adjust the menu position by the screen size:
//---------------------------------------------
CRect rectScreen;
MONITORINFO mi;
mi.cbSize = sizeof (MONITORINFO);
if (GetMonitorInfo (MonitorFromPoint (CPoint (m_x, m_y), MONITOR_DEFAULTTONEAREST),
&mi))
{
rectScreen = mi.rcWork;
}
else
{
::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0);
}
if (m_x + size.cx > rectScreen.right)
{
//-----------------------------------------------------
// Menu can't be overlapped with the parent popup menu!
//-----------------------------------------------------
CBCGPToolBar* pParentBar = m_pParentBtn == NULL ? NULL :
DYNAMIC_DOWNCAST (CBCGPToolBar, m_pParentBtn->m_pWndParent);
if (pParentBar != NULL &&
(pParentBar->IsHorizontal ()) == 0)
{
//------------------------------------------------
// Parent menu bar is docked vertical, place menu
// in the left or right side of the parent frame:
//------------------------------------------------
CRect rectParent;
pParentBar->GetWindowRect (rectParent);
m_x = rectParent.left - size.cx;
}
else
{
m_x = rectScreen.Width () - size.cx - 1;
}
}
if (m_y + size.cy > rectScreen.bottom)
{
m_y -= size.cy;
if (m_pParentBtn != NULL)
{
m_y -= m_pParentBtn->m_rect.Height () + 4;
}
else if (m_y < 0)
{
m_y = 0;
}
}
SetWindowPos (NULL, m_x, m_y, size.cx, size.cy,
SWP_NOZORDER | SWP_NOACTIVATE);
}
//****************************************************************************************
void CBCGPDropDownFrame::OnDestroy()
{
if (m_pParentBtn != NULL)
{
ASSERT (m_pParentBtn->m_pPopupMenu == this);
m_pParentBtn->m_pPopupMenu = NULL;
m_pParentBtn->m_nStyle = m_pParentBtn->m_nStyle & ~TBBS_PRESSED;
CBCGPToolBar* pparentBar = DYNAMIC_DOWNCAST(CBCGPToolBar, m_pParentBtn->m_pWndParent);
if (pparentBar)
{
CPoint point;
::GetCursorPos(&point);
pparentBar->ScreenToClient(&point);
pparentBar->SendMessage(WM_LBUTTONUP, NULL, MAKELONG(point.x, point.y));
}
}
CMiniFrameWnd::OnDestroy();
}
//****************************************************************************************
void CBCGPDropDownFrame::PostNcDestroy()
{
if (m_pParentBtn != NULL)
{
m_pParentBtn->OnCancelMode ();
}
CMiniFrameWnd::PostNcDestroy();
}
//****************************************************************************************
CBCGPDropDownFrame* CBCGPDropDownFrame::GetParentPopupMenu () const
{
if (m_pParentBtn == NULL)
{
return NULL;
}
CBCGPPopupMenuBar* pParentBar =
DYNAMIC_DOWNCAST (CBCGPPopupMenuBar, m_pParentBtn->m_pWndParent);
if (pParentBar != NULL)
{
CBCGPDropDownFrame* pParentMenu =
DYNAMIC_DOWNCAST (CBCGPDropDownFrame, pParentBar->GetParentFrame ());
ASSERT_VALID (pParentMenu);
return pParentMenu;
}
else
{
return NULL;
}
}
//****************************************************************************************
CBCGPMenuBar* CBCGPDropDownFrame::GetParentMenuBar () const
{
if (m_pParentBtn == NULL)
{
return NULL;
}
CBCGPMenuBar* pParentBar =
DYNAMIC_DOWNCAST (CBCGPMenuBar, m_pParentBtn->m_pWndParent);
return pParentBar;
}
//****************************************************************************************
BOOL CBCGPDropDownFrame::OnEraseBkgnd(CDC* pDC)
{
CRect rectClient; // Client area rectangle
GetClientRect (&rectClient);
pDC->FillSolidRect (rectClient, globalData.clrBarFace);
return TRUE;
}
//************************************************************************************
#if _MSC_VER >= 1300
void CBCGPDropDownFrame::OnActivateApp(BOOL bActive, DWORD /*dwThreadID*/)
#else
void CBCGPDropDownFrame::OnActivateApp(BOOL bActive, HTASK /*hTask*/)
#endif
{
if (!bActive && !CBCGPToolBar::IsCustomizeMode ())
{
SendMessage (WM_CLOSE);
}
}
IMPLEMENT_SERIAL(CBCGPDropDownToolbarButton, CBCGPToolbarButton, VERSIONABLE_SCHEMA | 1)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBCGPDropDownToolbarButton::CBCGPDropDownToolbarButton()
{
m_pToolBar = NULL;
m_pPopupMenu = NULL;
m_pWndParent = NULL;
m_uiTimer = 0;
m_bLocked = TRUE;
m_iSelectedImage = 0;
m_bInternalDraw = FALSE;
m_bLocalUserButton = FALSE;
}
//*****************************************************************************************
CBCGPDropDownToolbarButton::CBCGPDropDownToolbarButton (LPCTSTR lpszName, CBCGPDropDownToolBar* pToolBar)
{
ASSERT (lpszName != NULL);
m_strName = lpszName;
m_uiTimer = 0;
m_pPopupMenu = NULL;
m_pWndParent = NULL;
ASSERT_VALID (pToolBar);
m_pToolBar = pToolBar;
CBCGPToolbarButton* pbutton = pToolBar->GetButton (0);
if (pbutton == NULL) // Toolbar is empty!
{
ASSERT (FALSE);
}
else
{
CBCGPToolbarButton::CopyFrom (*pbutton);
}
m_iSelectedImage = 0;
m_bLocalUserButton = FALSE;
}
//*****************************************************************************************
CBCGPDropDownToolbarButton::~CBCGPDropDownToolbarButton()
{
}
//****************************************************************************************
void CBCGPDropDownToolbarButton::SetDefaultCommand (UINT uiCmd)
{
ASSERT_VALID (m_pToolBar);
m_nID = uiCmd;
//------------------
// Find image index:
//------------------
int iImage = 0;
m_iSelectedImage = -1;
for (int i = 0; i < m_pToolBar->GetCount (); i ++)
{
CBCGPToolbarButton* pButton = m_pToolBar->GetButton (i);
ASSERT_VALID (pButton);
if (pButton->m_nStyle & TBBS_SEPARATOR)
{
continue;
}
if (pButton->m_nID == uiCmd)
{
m_bLocalUserButton = pButton->m_bUserButton;
if (m_bLocalUserButton)
{
m_iSelectedImage = pButton->GetImage();
}
else
{
m_iSelectedImage = iImage;
}
break;
}
iImage ++;
}
if (m_iSelectedImage == -1)
{
ASSERT (FALSE);
m_iSelectedImage = 0;
}
}
//////////////////////////////////////////////////////////////////////
// Overrides:
void CBCGPDropDownToolbarButton::CopyFrom (const CBCGPToolbarButton& s)
{
CBCGPToolbarButton::CopyFrom (s);
const CBCGPDropDownToolbarButton& src = (const CBCGPDropDownToolbarButton&) s;
m_pToolBar = src.m_pToolBar;
m_strName = src.m_strName;
m_iSelectedImage = src.m_iSelectedImage;
m_bDragFromCollection = FALSE;
}
//*****************************************************************************************
void CBCGPDropDownToolbarButton::Serialize (CArchive& ar)
{
CBCGPToolbarButton::Serialize (ar);
UINT uiToolbarResID = 0;
if (ar.IsLoading ())
{
m_pToolBar = NULL;
ar >> uiToolbarResID;
ar >> m_strName;
ar >> m_iSelectedImage;
// Find toolbar with required resource ID:
for (POSITION pos = gAllToolbars.GetHeadPosition (); pos != NULL;)
{
CBCGPDropDownToolBar* pToolBar = DYNAMIC_DOWNCAST (CBCGPDropDownToolBar,
gAllToolbars.GetNext (pos));
if (pToolBar != NULL &&
CWnd::FromHandlePermanent (pToolBar->m_hWnd) != NULL)
{
ASSERT_VALID (pToolBar);
if (pToolBar->m_uiOriginalResID == uiToolbarResID)
{
m_pToolBar = pToolBar;
break;
}
}
}
SetDefaultCommand (m_nID);
}
else
{
if (m_pToolBar == NULL)
{
ASSERT (FALSE);
}
else
{
ASSERT_VALID (m_pToolBar);
uiToolbarResID = m_pToolBar->m_uiOriginalResID;
}
ar << uiToolbarResID;
ar << m_strName;
ar << m_iSelectedImage;
}
}
//*****************************************************************************************
void CBCGPDropDownToolbarButton::OnDraw (CDC* pDC, const CRect& rect, CBCGPToolBarImages* pImages,
BOOL bHorz, BOOL bCustomizeMode, BOOL bHighlight, BOOL bDrawBorder, BOOL bGrayDisabledButtons)
{
ASSERT_VALID (pDC);
//----------------------
// Fill button interior:
//----------------------
FillInterior (pDC, rect, bHighlight);
int nActualArrowSize =
CBCGPToolBar::IsLargeIcons () ? nArrowSize * 2 : nArrowSize;
int nHalfArrowSize =
CBCGPToolBar::IsLargeIcons () ? nArrowSize : nArrowSize / 2 + 1;
CRect rectParent = rect;
rectParent.right -= nActualArrowSize / 2 + 1;
if (m_pToolBar != NULL)
{
CBCGPDrawState ds;
BOOL bImage = m_bImage;
m_bInternalDraw = TRUE;
if (!m_bLocalUserButton)
{
m_pToolBar->m_ImagesLocked.SetTransparentColor (globalData.clrBtnFace);
m_pToolBar->m_ImagesLocked.PrepareDrawImage (ds, m_pToolBar->GetImageSize ());
}
else
{
m_pToolBar->m_pUserImages->SetTransparentColor (globalData.clrBtnFace);
m_pToolBar->m_pUserImages->PrepareDrawImage (ds, m_pToolBar->GetImageSize ());
}
m_iImage = m_iSelectedImage;
m_iUserImage = m_iSelectedImage;
m_bImage = TRUE;
BOOL bDisableFill = m_bDisableFill;
m_bDisableFill = TRUE;
if (m_bLocalUserButton)
{
m_bUserButton = m_bLocalUserButton;
CBCGPToolbarButton::OnDraw(pDC, rect, m_pToolBar->m_pUserImages, bHorz, bCustomizeMode, bHighlight, FALSE, bGrayDisabledButtons);
m_bUserButton = FALSE;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -