bcgmenubar.cpp
来自「用bcg库编写的java IDE 源码」· C++ 代码 · 共 1,479 行 · 第 1/3 页
CPP
1,479 行
}
//**************************************************************************************
void CBCGMenuBar::OnSetFocus(CWnd* pOldWnd)
{
CBCGToolBar::OnSetFocus(pOldWnd);
if (GetDroppedDownMenu () == NULL)
{
GetOwner()->SendMessage (WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE);
int iFirstItem = (m_bMaximizeMode) ? 1 : 0;
if (m_iHighlighted < 0 && iFirstItem < GetCount ())
{
m_iHighlighted = iFirstItem;
InvalidateButton (iFirstItem);
}
}
}
//**************************************************************************************
BOOL CBCGMenuBar::Create(CWnd* pParentWnd,
DWORD dwStyle,
UINT nID)
{
m_pParentWnd = pParentWnd;
return CBCGToolBar::Create (pParentWnd, dwStyle, nID);
}
//***************************************************************************************
LRESULT CALLBACK CBCGMenuBar::BCGMenuBarMouseProc (int nCode, WPARAM wParam, LPARAM lParam)
{
MOUSEHOOKSTRUCT* lpMS = (MOUSEHOOKSTRUCT*) lParam;
ASSERT (lpMS != NULL);
if (wParam == WM_LBUTTONUP || wParam == WM_NCLBUTTONUP)
{
if (m_pDraggedMenuBar != NULL &&
m_pDraggedMenuBar->m_pDockContext != NULL &&
m_pDraggedMenuBar->m_pDockContext->m_bDragging)
{
//------------------------------------------------------------------------
// End of dragging. Don't allow the menubar to be docked on the right side
// of any control bars!
//------------------------------------------------------------------------
m_pDraggedMenuBar->m_pDockContext->m_rectDragVert.top = 0;
m_pDraggedMenuBar->m_pDockContext->m_rectDragHorz.left = 0;
m_pDraggedMenuBar->SetDragMode (FALSE);
}
}
return CallNextHookEx (m_hookMouseDrag, nCode, wParam, lParam);
}
//************************************************************************************************
void CBCGMenuBar::SetDragMode (BOOL bOn)
{
if (bOn)
{
if (m_hookMouseDrag == NULL) // Not installed yet, set it now!
{
m_hookMouseDrag = ::SetWindowsHookEx (WH_MOUSE, BCGMenuBarMouseProc,
0, GetCurrentThreadId ());
if (m_hookMouseDrag == NULL)
{
TRACE (_T("CBCGMenuBar: Can't set mouse hook!\n"));
return;
}
}
m_pDraggedMenuBar = this;
}
else
{
if (m_hookMouseDrag != NULL)
{
::UnhookWindowsHookEx (m_hookMouseDrag);
m_hookMouseDrag = NULL;
}
m_pDraggedMenuBar = NULL;
}
}
//************************************************************************************************
void CBCGMenuBar::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
CBCGToolBar::OnWindowPosChanged(lpwndpos);
SetDragMode (FALSE);
}
//*****************************************************************************************
CSize CBCGMenuBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
if (m_Buttons.IsEmpty ())
{
return GetButtonSize ();
}
DWORD dwMode = bStretch ? LM_STRETCH : 0;
dwMode |= bHorz ? LM_HORZ : 0;
return CalcLayout (dwMode);
}
//*****************************************************************************************
BOOL CBCGMenuBar::OnSetDefaultButtonText (CBCGToolbarButton* pButton)
{
ASSERT_VALID (pButton);
CString strText;
if (FindMenuItemText (m_hMenu, pButton->m_nID, strText))
{
pButton->m_strText = strText;
return TRUE;
}
return CBCGToolBar::OnSetDefaultButtonText (pButton);
}
//****************************************************************************************
BOOL CBCGMenuBar::FindMenuItemText (HMENU hMenu, const UINT nItemID, CString& strOutText)
{
if (hMenu == NULL || nItemID == 0 || nItemID == (UINT) -1)
{
return FALSE;
}
CMenu* pMenu = CMenu::FromHandle (hMenu);
if (pMenu == NULL)
{
return FALSE;
}
int iCount = (int) pMenu->GetMenuItemCount ();
for (int i = 0; i < iCount; i ++)
{
UINT uiID = pMenu->GetMenuItemID (i);
if (uiID == nItemID) // Found!
{
pMenu->GetMenuString (i, strOutText, MF_BYPOSITION);
return TRUE;
}
else if (uiID == -1) // Pop-up menu
{
CMenu* pPopupMenu = pMenu->GetSubMenu (i);
ASSERT (pPopupMenu != NULL);
if (FindMenuItemText (pPopupMenu->GetSafeHmenu (), nItemID, strOutText))
{
return TRUE;
}
}
}
return FALSE;
}
//*****************************************************************************************
BOOL CBCGMenuBar::PrevMenu ()
{
int iHot;
CBCGToolbarMenuButton* pCurrPopupMenu = GetDroppedDownMenu (&iHot);
if (pCurrPopupMenu == NULL)
{
return FALSE;
}
int iTotalItems = GetCount ();
if (m_bMaximizeMode)
{
iTotalItems -= m_nSystemButtonsNum;
}
if ( --iHot < 0)
{
iHot = iTotalItems - 1;
}
//-------------------------------------------
// Save animation type and disable animation:
//-------------------------------------------
CBCGPopupMenu::ANIMATION_TYPE animType = CBCGPopupMenu::GetAnimationType ();
CBCGPopupMenu::SetAnimationType (CBCGPopupMenu::NO_ANIMATION);
OnChangeHot (iHot);
//-----------------------
// Select the first item:
//-----------------------
if (m_iHot >= 0)
{
CBCGToolbarMenuButton* pMenuButton =
DYNAMIC_DOWNCAST (CBCGToolbarMenuButton, GetButton (m_iHot));
if (pMenuButton != NULL && pMenuButton->m_pPopupMenu != NULL)
{
pMenuButton->m_pPopupMenu->SendMessage (WM_KEYDOWN, VK_HOME);
}
}
//-------------------
// Restore animation:
//-------------------
CBCGPopupMenu::SetAnimationType (animType);
return TRUE;
}
//*****************************************************************************************
BOOL CBCGMenuBar::NextMenu ()
{
int iHot;
CBCGToolbarMenuButton* pCurrPopupMenu = GetDroppedDownMenu (&iHot);
if (pCurrPopupMenu == NULL)
{
return FALSE;
}
int iTotalItems = GetCount ();
if (m_bMaximizeMode)
{
iTotalItems -= m_nSystemButtonsNum;
}
if (++ iHot >= iTotalItems)
{
iHot = 0;
}
//-------------------------------------------
// Save animation type and disable animation:
//-------------------------------------------
CBCGPopupMenu::ANIMATION_TYPE animType = CBCGPopupMenu::GetAnimationType ();
CBCGPopupMenu::SetAnimationType (CBCGPopupMenu::NO_ANIMATION);
OnChangeHot (iHot);
//-----------------------
// Select the first item:
//-----------------------
if (m_iHot >= 0)
{
CBCGToolbarMenuButton* pMenuButton =
DYNAMIC_DOWNCAST (CBCGToolbarMenuButton, GetButton (m_iHot));
if (pMenuButton != NULL && pMenuButton->m_pPopupMenu != NULL)
{
pMenuButton->m_pPopupMenu->SendMessage (WM_KEYDOWN, VK_HOME);
}
}
//-------------------
// Restore animation:
//-------------------
CBCGPopupMenu::SetAnimationType (animType);
return TRUE;
}
//******************************************************************************************
int CBCGMenuBar::FindDropIndex (const CPoint point, CRect& rectDrag) const
{
int iIndex = CBCGToolBar::FindDropIndex (point, rectDrag);
if (m_bMaximizeMode && iIndex >= 0)
{
//--------------------------------------
// Maybe drag left from the system icon?
//--------------------------------------
if (iIndex == 0)
{
return -1;
}
//-----------------------------------------
// Maybe drag right of the system buttons?
//-----------------------------------------
if (iIndex > GetCount () - m_nSystemButtonsNum)
{
iIndex = GetCount () - m_nSystemButtonsNum;
}
}
return iIndex;
}
//****************************************************************************************
void CBCGMenuBar::OnChangeHot (int iHot)
{
CBCGToolBar::OnChangeHot (iHot);
KillTimer (uiShowAllItemsTimerId);
if (GetDroppedDownMenu () == NULL)
{
m_bShowAllCommands = FALSE;
}
else
{
SetTimer (uiShowAllItemsTimerId, iShowAllItemsTimerFreq, NULL);
}
}
//****************************************************************************************
void CBCGMenuBar::SetShowAllCommands (BOOL bShowAllCommands)
{
m_bShowAllCommands = bShowAllCommands;
}
//***************************************************************************************
CBCGToolbarButton* CBCGMenuBar::GetMenuItem (int iItem) const
{
if (m_bMaximizeMode)
{
iItem --; // Ignore system-menu button
}
return GetButton (iItem);
}
//***************************************************************************************
CBCGToolbarSystemMenuButton* CBCGMenuBar::GetSystemMenu () const
{
if (!m_bMaximizeMode)
{
return NULL;
}
ASSERT (!m_Buttons.IsEmpty ());
return DYNAMIC_DOWNCAST (CBCGToolbarSystemMenuButton, m_Buttons.GetHead ());
}
//***************************************************************************************
CBCGToolbarMenuButtonsButton* CBCGMenuBar::GetSystemButton (UINT uiBtn, BOOL bByCommand) const
{
if (!m_bMaximizeMode)
{
return NULL;
}
if (bByCommand)
{
for (POSITION pos = m_Buttons.GetTailPosition (); pos != NULL;)
{
CBCGToolbarMenuButtonsButton* pButton =
DYNAMIC_DOWNCAST (CBCGToolbarMenuButtonsButton,
m_Buttons.GetPrev (pos));
if (pButton == NULL)
{
break;
}
if (pButton->m_nID == uiBtn)
{
return pButton;
}
}
return NULL;
}
// else - by index:
if ((int) uiBtn < 0 || (int) uiBtn >= m_nSystemButtonsNum)
{
ASSERT (FALSE);
return NULL;
}
int iIndex = m_Buttons.GetCount () - m_nSystemButtonsNum + uiBtn;
CBCGToolbarMenuButtonsButton* pButton =
DYNAMIC_DOWNCAST (CBCGToolbarMenuButtonsButton, GetButton (iIndex));
ASSERT_VALID (pButton);
return pButton;
}
//************************************************************************************
BOOL CBCGMenuBar::SetMenuFont (LPLOGFONT lpLogFont, BOOL bHorz)
{
if (!globalData.SetMenuFont (lpLogFont, bHorz))
{
return FALSE;
}
//-------------------------------------------
// Recalculate all toolbars and menus layout:
//-------------------------------------------
extern CObList gAllToolbars;
for (POSITION pos = gAllToolbars.GetHeadPosition (); pos != NULL;)
{
CBCGToolBar* pToolBar = (CBCGToolBar*) gAllToolbars.GetNext (pos);
ASSERT (pToolBar != NULL);
if (CWnd::FromHandlePermanent (pToolBar->m_hWnd) != NULL)
{
ASSERT_VALID(pToolBar);
pToolBar->AdjustLayout ();
}
}
return TRUE;
}
//************************************************************************************
inline const CFont& CBCGMenuBar::GetMenuFont (BOOL bHorz)
{
return bHorz ? globalData.fontRegular : globalData.fontVert;
}
//************************************************************************************
void CBCGMenuBar::OnTimer(UINT nIDEvent)
{
if (nIDEvent == uiShowAllItemsTimerId)
{
CPoint ptCursor;
::GetCursorPos (&ptCursor);
ScreenToClient (&ptCursor);
//--------------------------------------------------------------
// Check that the popup-menu is still exist and mouse cursor is
// within the menu button:
//--------------------------------------------------------------
CBCGToolbarMenuButton* pMenuButon = GetDroppedDownMenu ();
if (pMenuButon != NULL && pMenuButon->m_pPopupMenu != NULL &&
pMenuButon->m_rect.PtInRect (ptCursor) &&
!pMenuButon->m_pPopupMenu->AreAllCommandsShown ())
{
pMenuButon->m_pPopupMenu->ShowAllCommands ();
}
KillTimer (uiShowAllItemsTimerId);
}
CBCGToolBar::OnTimer(nIDEvent);
}
//*******************************************************************************************
void CBCGMenuBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CBCGToolBar::OnLButtonDblClk(nFlags, point);
if (IsShowAllCommands () || IsCustomizeMode ())
{
return;
}
int iButton = HitTest(point);
if (iButton < 0)
{
return;
}
CBCGToolbarMenuButton* pMenuButton = DYNAMIC_DOWNCAST (CBCGToolbarMenuButton, GetButton(iButton));
if (pMenuButton == NULL)
{
return;
}
//////////////////////////////////////////////
// Add by Yuhu.Wang on 99/11/04
// Special deal to system menu button
//--------------------------------------------
if(pMenuButton->IsKindOf (RUNTIME_CLASS (CBCGToolbarSystemMenuButton)))
{
return;
}
//--------------------------------------------
//////////////////////////////////////////////
m_bShowAllCommands = TRUE;
pMenuButton->OnCancelMode ();
if (pMenuButton->OnClick (this, FALSE))
{
OnChangeHot (iButton);
InvalidateButton (iButton);
UpdateWindow(); // immediate feedback
}
}
//***********************************************************************************
void CBCGMenuBar::CalcSysButtonSize ()
{
CWindowDC dc (NULL);
CDC dcMem;
dcMem.CreateCompatibleDC (NULL); // Assume display!
int iButtonWidth = ::GetSystemMetrics (SM_CXSIZE);
int iButtonHeight = ::GetSystemMetrics (SM_CYSIZE);
CBitmap bmpMem;
bmpMem.CreateCompatibleBitmap (&dc, iButtonWidth, iButtonHeight);
CBitmap* pBmpOriginal = dcMem.SelectObject (&bmpMem);
CRect rectBtn (0, 0, iButtonWidth, iButtonHeight);
dcMem.DrawFrameControl (rectBtn, DFC_CAPTION, DFCS_ADJUSTRECT);
m_szSystemButton = rectBtn.Size ();
dcMem.SelectObject (pBmpOriginal);
}
//*********************************************************************************
void CBCGMenuBar::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
{
CBCGToolBar::OnSettingChange(uFlags, lpszSection);
CalcSysButtonSize ();
Invalidate ();
UpdateWindow ();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?