📄 bcgppopupmenu.cpp
字号:
{
SetTimer (iScrollTimerId, iScrollTimerDuration, NULL);
}
}
//****************************************************************************************
BOOL CBCGPPopupMenu::IsScrollUpAvailable ()
{
CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
ASSERT_VALID (pMenuBar);
return pMenuBar->GetOffset () > 0;
}
//****************************************************************************************
BOOL CBCGPPopupMenu::IsScrollDnAvailable ()
{
CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
ASSERT_VALID (pMenuBar);
if (pMenuBar->GetCount () == 0)
{
return FALSE;
}
CRect rectLastItem;
pMenuBar->GetItemRect (pMenuBar->GetCount () - 1, rectLastItem);
return rectLastItem.bottom > m_nMenuBarHeight + pMenuBar->GetRowHeight ();
}
//****************************************************************************************
void CBCGPPopupMenu::CollapseSubmenus ()
{
CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
ASSERT_VALID (pMenuBar);
for (POSITION pos = pMenuBar->m_Buttons.GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton =
(CBCGPToolbarButton*) pMenuBar->m_Buttons.GetNext (pos);
ASSERT (pButton != NULL);
pButton->OnCancelMode ();
}
}
//****************************************************************************************
void CBCGPPopupMenu::DrawImage (CDC* pDC, const CRect& rect, int iImage, BOOL bDrawFrame)
{
CRect rectImage (CPoint (0, 0), CMenuImages::Size ());
CRect rectFill = rect;
rectFill.top -= 2;
pDC->FillRect (rectFill, &globalData.brBtnFace);
CPoint point (
rect.left + (rect.Width () - rectImage.Width ()) / 2,
rect.top + (rect.Height () - rectImage.Height ()) / 2);
CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage, point);
if (bDrawFrame)
{
pDC->Draw3dRect (rect,
globalData.clrBarHilite,
globalData.clrBarShadow);
}
}
//****************************************************************************************
void CBCGPPopupMenu::ShowAllCommands ()
{
CBCGPToolbarMenuButton* pParentMenuButton =
DYNAMIC_DOWNCAST (CBCGPToolbarMenuButton, m_pParentBtn);
if (pParentMenuButton != NULL)
{
CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
ASSERT_VALID (pMenuBar);
pMenuBar->SetHot (NULL);
CBCGPMenuBar::SetShowAllCommands ();
// Play standard menu popup sound!
BCGPlaySystemSound (BCGSOUND_MENU_POPUP);
ShowWindow (SW_HIDE);
m_bShown = FALSE;
if (m_bmpShadowRight.GetSafeHandle () != NULL)
{
m_bmpShadowRight.DeleteObject ();
}
if (m_bmpShadowBottom.GetSafeHandle () != NULL)
{
m_bmpShadowBottom.DeleteObject ();
}
m_ptLocation = m_ptLocationInitial;
InitMenuBar ();
UpdateBottomWindows ();
ShowWindow (SW_SHOWNOACTIVATE);
if (pParentMenuButton->m_pWndParent != NULL
&& ::IsWindow (pParentMenuButton->m_pWndParent->m_hWnd))
{
pParentMenuButton->m_pWndParent->InvalidateRect (
pParentMenuButton->Rect ());
pParentMenuButton->m_pWndParent->UpdateWindow ();
}
}
}
//**************************************************************************************
void CBCGPPopupMenu::SetMaxWidth (int iMaxWidth)
{
if (iMaxWidth == m_iMaxWidth)
{
return;
}
m_iMaxWidth = iMaxWidth;
if (GetSafeHwnd () == NULL)
{
return;
}
CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
ASSERT_VALID (pMenuBar);
if (!::IsWindow (m_hWnd) ||
!::IsWindow (pMenuBar->m_hWnd))
{
return;
}
pMenuBar->m_iMaxWidth = m_iMaxWidth;
RecalcLayout ();
}
//*************************************************************************************
BOOL CBCGPPopupMenu::InitMenuBar ()
{
CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
ASSERT_VALID (pMenuBar);
if (m_hMenu != NULL)
{
ASSERT (::IsMenu (m_hMenu));
if (m_pParentBtn != NULL ||
!g_menuHash.LoadMenuBar (m_hMenu, pMenuBar))
{
//-------------------------------------------
// Failed to restore, load the default state:
//-------------------------------------------
if (CBCGPMenuBar::IsShowAllCommands())
{
if (!pMenuBar->ImportFromMenu (m_hMenu, TRUE))
{
TRACE(_T("Can't import menu\n"));
return FALSE;
}
}else
{
if (!pMenuBar->ImportFromMenu (m_hMenu, !HideRarelyUsedCommands ()))
{
TRACE(_T("Can't import menu\n"));
return FALSE;
}
}
}
}
POSITION pos;
//----------------------------------------
// Maybe, we should process the MRU files:
//----------------------------------------
CRecentFileList* pMRUFiles =
((CBCGPApp*) AfxGetApp ())->m_pRecentFileList;
if (pMRUFiles != NULL && !CBCGPToolBar::IsCustomizeMode ())
{
int iMRUItemIndex = 0;
BOOL bIsPrevSeparator = FALSE;
for (pos = pMenuBar->m_Buttons.GetHeadPosition ();
pos != NULL; iMRUItemIndex ++)
{
POSITION posSave = pos;
CBCGPToolbarButton* pButton =
(CBCGPToolbarButton*) pMenuBar->m_Buttons.GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nID == ID_FILE_MRU_FILE1 &&
pButton->m_strText == _T("Recent File"))
{
//------------------------------
// Remove dummy item ("Recent"):
//------------------------------
pMenuBar->m_Buttons.RemoveAt (posSave);
delete pButton;
TCHAR szCurDir [_MAX_PATH];
::GetCurrentDirectory (_MAX_PATH, szCurDir);
int nCurDir = lstrlen (szCurDir);
ASSERT (nCurDir >= 0);
szCurDir [nCurDir] = _T('\\');
szCurDir [++ nCurDir] = _T('\0');
//---------------
// Add MRU files:
//---------------
int iNumOfFiles = 0; // Actual added to menu
for (int i = 0; i < pMRUFiles->GetSize (); i ++)
{
CString strName;
if (pMRUFiles->GetDisplayName (strName, i,
szCurDir, nCurDir))
{
//---------------------
// Add shortcut number:
//---------------------
CString strItem;
strItem.Format (_T("&%d %s"), ++iNumOfFiles, strName);
pMenuBar->InsertButton (
CBCGPToolbarMenuButton (
ID_FILE_MRU_FILE1 + i, NULL,
-1, strItem),
iMRUItemIndex ++);
}
}
//------------------------------------------------------
// Usualy, the MRU group is "covered" by two seperators.
// If MRU list is empty, remove redandant separator:
//------------------------------------------------------
if (iNumOfFiles == 0 && // No files were added
bIsPrevSeparator && // Prev. button was separator
pos != NULL) // Not a last button
{
posSave = pos;
pButton = (CBCGPToolbarButton*)
pMenuBar->m_Buttons.GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nStyle & TBBS_SEPARATOR)
{
//---------------------------------------
// Next button also separator, remove it:
//---------------------------------------
pMenuBar->m_Buttons.RemoveAt (posSave);
delete pButton;
}
}
break;
}
bIsPrevSeparator = (pButton->m_nStyle & TBBS_SEPARATOR);
}
}
//--------------------------
// Setup user-defined tools:
//--------------------------
if (g_pUserToolsManager != NULL && !CBCGPToolBar::IsCustomizeMode ())
{
BOOL bToolsAreReady = FALSE;
int iToolItemIndex = 0;
BOOL bIsPrevSeparator = FALSE;
for (pos = pMenuBar->m_Buttons.GetHeadPosition (); pos != NULL; iToolItemIndex ++)
{
POSITION posSave = pos;
CBCGPToolbarButton* pButton =
(CBCGPToolbarButton*) pMenuBar->m_Buttons.GetNext (pos);
ASSERT (pButton != NULL);
if (g_pUserToolsManager->GetToolsEntryCmd () == pButton->m_nID)
{
//----------------------------------------------------
// Replace dummy tools command by the user tools list:
//----------------------------------------------------
pMenuBar->m_Buttons.RemoveAt (posSave);
delete pButton;
if (!bToolsAreReady)
{
const CObList& lstTools = g_pUserToolsManager->GetUserTools ();
if (!bIsPrevSeparator && !lstTools.IsEmpty () &&
!pMenuBar->m_Buttons.IsEmpty ())
{
//-------------------------------------
// Add separator before the first tool:
//-------------------------------------
pMenuBar->InsertSeparator (iToolItemIndex++);
}
for (POSITION posTool = lstTools.GetHeadPosition (); posTool != NULL;)
{
CBCGPUserTool* pTool = (CBCGPUserTool*) lstTools.GetNext (posTool);
ASSERT_VALID (pTool);
//----------------------------------------------
// Is user tool associated with the user image?
//----------------------------------------------
int iUserImage = CMD_MGR.GetCmdImage (pTool->GetCommandId (), TRUE);
pMenuBar->InsertButton (
CBCGPToolbarMenuButton (
pTool->GetCommandId (), NULL,
iUserImage == -1 ? 0 : iUserImage, pTool->m_strLabel,
iUserImage != -1),
iToolItemIndex ++);
}
if (pos != NULL)
{
//-------------------------------------
// Add separator after the last tool:
//-------------------------------------
pMenuBar->InsertSeparator (iToolItemIndex++);
bIsPrevSeparator = TRUE;
}
bToolsAreReady = TRUE;
}
}
else if (pButton->m_nStyle & TBBS_SEPARATOR)
{
if (bIsPrevSeparator)
{
pMenuBar->m_Buttons.RemoveAt (posSave);
delete pButton;
}
bIsPrevSeparator = TRUE;
}
else
{
bIsPrevSeparator = FALSE;
}
}
}
CFrameWnd* pTarget = (CFrameWnd*) pMenuBar->GetCommandTarget ();
if (pTarget == NULL || !pTarget->IsFrameWnd())
{
pTarget = BCGPGetParentFrame(this);
}
if (pTarget != NULL)
{
pMenuBar->OnUpdateCmdUI(pTarget, FALSE);
}
//-----------------------------------------------------------------------------
// Maybe, main application frame should update the popup menu context before it
// displayed (example - windows list):
//-----------------------------------------------------------------------------
if (!ActivatePopupMenu (BCGCBProGetTopLevelFrame (this), this))
{
return FALSE;
}
RecalcLayout ();
return TRUE;
}
//************************************************************************************
BOOL CBCGPPopupMenu::HideRarelyUsedCommands () const
{
return (m_pParentBtn != NULL);
}
//************************************************************************************
void CBCGPPopupMenu::UpdateBottomWindows (BOOL bCheckOnly)
{
if (m_iShadowSize > 0)
{
CWnd* pWndMain = GetTopLevelParent ();
if (pWndMain != NULL)
{
//---------------------------------------------------------
// If menu will be shown outside of the application window,
// don't show shadows!
//---------------------------------------------------------
CRect rectMain;
pWndMain->GetWindowRect (rectMain);
CRect rectMenu (m_ptLocation,
CSize (m_FinalSize.cx + m_iShadowSize, m_FinalSize.cy + m_iShadowSize));
CRect rectInter;
rectInter.UnionRect (&rectMenu, &rectMain);
if (rectInter != rectMain && !GetForceShadow ())
{
m_iShadowSize = 0;
if (!bCheckOnly)
{
SetWindowPos (NULL, -1, -1, m_FinalSize.cx, m_FinalSize.cy,
SWP_NOMOVE | SWP_NOZORDER |
SWP_NOACTIVATE);
}
}
else
{
pWndMain->UpdateWindow ();
}
}
}
}
//*************************************************************************************
void CBCGPPopupMenu::DoPaint (CDC* pPaintDC)
{
CRect rectClient; // Client area rectangle
GetClientRect (&rectClient);
BOOL bDrawShadows = m_iShadowSize != 0 &&
!CBCGPToolBar::IsCustomizeMode ();
if (bDrawShadows)
{
rectClient.right -= m_iShadowSize;
rectClient.bottom -= m_iShadowSize;
const int iMinBrightness = 100;
const int iMaxBrightness = 65;
//--------------------------------------------
// Draw the shadow, exclude the parent button:
//--------------------------------------------
CRect rectParentBtn;
rectParentBtn.SetRectEmpty ();
if (m_pParentBtn != NULL && GetParentPopupMenu () == NULL)
{
CWnd* pWnd = m_pParentBtn->GetParentWnd();
if (pWnd!= NULL && pWnd->GetSafeHwnd() != NULL)
{
rectParentBtn = m_pParentBtn->Rect ();
rectParentBtn.right--;
rectParentBtn.bottom--;
pWnd->MapWindowPoints(this, &rectParentBtn);
}
}
//--------------------------------------------------------------
// Prevent shadow drawing over Quick Customize Add-Remove button
//--------------------------------------------------------------
if (CBCGPVisualManager::GetInstance ()->IsOfficeXPStyleMenus ())
{
CBCGPPopupMenu* pParentPopup = GetParentPopupMenu ();
if (pParentPopup != NULL)
{
ASSERT_VALID (pParentPopup);
CBCGPToolbarMenuButton* pParentBtn = GetParentButton ();
if ((pParentBtn != NULL) && (pParentBtn->IsQuickMode ()))
{
if (pParentPopup->IsQuickCustomize ())
{
if (!m_bQuickCusomize && (m_DropDirection == DROP_DIRECTION_LEFT))
{
CWnd* pWnd = m_pParentBtn->GetParentWnd ();
if (pWnd != NULL && pWnd->GetSafeHwnd () != NULL)
{
rectParentBtn = m_pParentBtn->Rect ();
rectParentBtn.bottom += 2;
pWnd->MapWindowPoints (this, &rectParentBtn);
}
}
}
}
}
}
CBCGPVisualManager::GetInstance ()->OnDrawMenuShadow (
pPaintDC, rectClient, rectParentBtn,
m_iShadowSize, iMinBrightness, iMaxBrightness,
&m_bmpShadowBottom, &m_bmpShadowRight);
}
CBCGPVisualManager::GetInstance ()->OnDrawMenuBorder (pPaintDC, this, rectClient);
const int nBorderSize = CBCGPVisualManager::GetInstance ()->GetPopupMenuBorderSize ();
rectClient.DeflateRect (nBorderSize, nBorderSize);
//---------------------------
// Draw menu logo (if exist):
//---------------------------
if (m_iLogoWidth > 0)
{
CRect rectLogo = rectClient;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -