bcgmenubar.cpp
来自「用bcg库编写的java IDE 源码」· C++ 代码 · 共 1,479 行 · 第 1/3 页
CPP
1,479 行
if (nHit != -1)
{
CBCGToolbarButton* pButton = GetButton (nHit);
if (pButton == NULL ||
pButton->IsKindOf (RUNTIME_CLASS (CBCGToolbarMenuButton)))
{
//-----------------------------------
// Don't show tooltips on menu items!
//-----------------------------------
return -1;
}
}
return CBCGToolBar::OnToolHitTest (point, pTI);
}
//*************************************************************************************
int CBCGMenuBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBCGToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
//------------------------------------
// Attach menubar to the parent frame:
//------------------------------------
//----------------------
// First, try MDI frame:
//----------------------
CBCGMDIFrameWnd* pWndParentMDIFrame =
DYNAMIC_DOWNCAST (CBCGMDIFrameWnd, m_pParentWnd);
if (pWndParentMDIFrame != NULL)
{
pWndParentMDIFrame->m_Impl.SetMenuBar (this);
}
else
{
CBCGFrameWnd* pWndParentFrame =
DYNAMIC_DOWNCAST (CBCGFrameWnd, m_pParentWnd);
if (pWndParentFrame != NULL)
{
pWndParentFrame->m_Impl.SetMenuBar (this);
}
else
{
CBCGOleIPFrameWnd* pOleFrame =
DYNAMIC_DOWNCAST (CBCGOleIPFrameWnd, GetParentFrame ());
if (pOleFrame != NULL)
{
pOleFrame->m_Impl.SetMenuBar (this);
}
}
}
//----------------------------
// Set default menu bar title:
//----------------------------
CBCGLocalResource locaRes;
CString strTitle;
strTitle.LoadString (IDS_BCGBARRES_MENU_BAR_TITLE);
SetWindowText (strTitle);
//-------------------------------------------------------------
// Force the menu bar to be hiden whren the in-place editing is
// is activated (server application shows its own menu):
//-------------------------------------------------------------
SetBarStyle (GetBarStyle() | CBRS_HIDE_INPLACE);
//------------------------------
// Calculate system button size:
//------------------------------
CalcSysButtonSize ();
return 0;
}
//*************************************************************************************
BOOL CBCGMenuBar::LoadState (LPCTSTR lpszProfileName, int nIndex, UINT /*uiID*/)
{
ASSERT (m_hDefaultMenu != NULL);
CString strProfileName = ::BCGGetRegPath (strMenuProfile, lpszProfileName);
//------------------------------------------------------------
// Save current maximize mode (system buttons are not saved!):
//------------------------------------------------------------
BOOL bMaximizeMode = m_bMaximizeMode;
SetMaximizeMode (FALSE);
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (m_bAutoDocMenus && pDocManager != NULL)
{
//---------------------------------------
// Walk all templates in the application:
//---------------------------------------
for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
{
CBCGMultiDocTemplate* pTemplate =
(CBCGMultiDocTemplate*) pDocManager->GetNextDocTemplate (pos);
ASSERT_VALID (pTemplate);
ASSERT_KINDOF (CDocTemplate, pTemplate);
//-----------------------------------------------------
// We are interessing CMultiDocTemplate objects with
// the sahred menu only....
//-----------------------------------------------------
if (!pTemplate->IsKindOf (RUNTIME_CLASS (CMultiDocTemplate)) ||
pTemplate->m_hMenuShared == NULL)
{
continue;
}
UINT uiMenuResId = pTemplate->GetResId ();
ASSERT (uiMenuResId != 0);
//---------------------------------------------------------------
// Load menubar from registry and associate it with the
// template shared menu:
//---------------------------------------------------------------
if (CBCGToolBar::LoadState (strProfileName, nIndex, uiMenuResId))
{
g_menuHash.SaveMenuBar (pTemplate->m_hMenuShared, this);
}
}
}
//----------------------
// Load defualt menubar:
//----------------------
if (CBCGToolBar::LoadState (strProfileName, nIndex, 0))
{
g_menuHash.SaveMenuBar (m_hDefaultMenu, this);
}
//----------------------
// Restore current menu:
//----------------------
if (bMaximizeMode)
{
RestoreMaximizeMode ();
}
if (m_hMenu != NULL && g_menuHash.LoadMenuBar (m_hMenu, this))
{
GetParentFrame ()->RecalcLayout ();
Invalidate ();
UpdateWindow ();
}
return TRUE;
}
//*************************************************************************************
BOOL CBCGMenuBar::SaveState (LPCTSTR lpszProfileName, int nIndex, UINT /*uiID*/)
{
ASSERT (m_hDefaultMenu != NULL);
CString strProfileName = ::BCGGetRegPath (strMenuProfile, lpszProfileName);
g_menuHash.SaveMenuBar (m_hMenu, this);
//------------------------------------------------------------
// Save current maximize mode (system buttons are not saved!):
//------------------------------------------------------------
BOOL bMaximizeMode = m_bMaximizeMode;
SetMaximizeMode (FALSE);
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (m_bAutoDocMenus && pDocManager != NULL)
{
//---------------------------------------
// Walk all templates in the application:
//---------------------------------------
for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
{
CBCGMultiDocTemplate* pTemplate =
(CBCGMultiDocTemplate*) pDocManager->GetNextDocTemplate (pos);
ASSERT_VALID (pTemplate);
ASSERT_KINDOF (CDocTemplate, pTemplate);
//-----------------------------------------------------
// We are interessing CMultiDocTemplate objects with
// the sahred menu only....
//-----------------------------------------------------
if (!pTemplate->IsKindOf (RUNTIME_CLASS (CMultiDocTemplate)) ||
pTemplate->m_hMenuShared == NULL)
{
continue;
}
UINT uiMenuResId = pTemplate->GetResId ();
ASSERT (uiMenuResId != 0);
//----------------------------------------------------------
// Load menubar associated with the template shared menu and
// save it in the registry:
//----------------------------------------------------------
if (g_menuHash.LoadMenuBar (pTemplate->m_hMenuShared, this))
{
CBCGToolBar::SaveState (strProfileName, nIndex, uiMenuResId);
}
}
}
//-------------------
// Save default menu:
//-------------------
if (g_menuHash.LoadMenuBar (m_hDefaultMenu, this))
{
CBCGToolBar::SaveState (strProfileName, nIndex, 0);
}
//----------------------
// Restore current menu:
//----------------------
if (m_hMenu != NULL && g_menuHash.LoadMenuBar (m_hMenu, this))
{
GetParentFrame ()->RecalcLayout ();
Invalidate ();
UpdateWindow ();
}
if (bMaximizeMode)
{
RestoreMaximizeMode ();
}
return TRUE;
}
//*****************************************************************************************
void CBCGMenuBar::OnLButtonDown(UINT nFlags, CPoint point)
{
int iHit = HitTest (point);
//--------------------------------------------------------
// Disable control bar dragging if any menues are dropped!
//--------------------------------------------------------
if (iHit < 0 && // Click outside of buttons
GetDroppedDownMenu () != NULL)
{
// Do nothing
}
else
{
CBCGToolBar::OnLButtonDown(nFlags, point);
}
}
//****************************************************************************************
BOOL CBCGMenuBar::TranslateChar (UINT nChar)
{
UINT nUpperChar = toupper (nChar);
CBCGToolbarButton* pButton = NULL;
if (!m_AcellKeys.Lookup (nUpperChar, pButton))
{
return FALSE;
}
ASSERT_VALID (pButton);
//-------------------------------------------
// Save animation type and disable animation:
//-------------------------------------------
CBCGPopupMenu::ANIMATION_TYPE animType = CBCGPopupMenu::GetAnimationType ();
CBCGPopupMenu::SetAnimationType (CBCGPopupMenu::NO_ANIMATION);
BOOL bRes = DropDownMenu (pButton);
//-------------------
// Restore animation:
//-------------------
CBCGPopupMenu::SetAnimationType (animType);
if(bRes)
{
return TRUE;
}
return ProcessCommand (pButton);
}
//****************************************************************************************
void CBCGMenuBar::OnCustomizeMode (BOOL bSet)
{
if (bSet)
{
m_bActualMaximizeMode = m_bMaximizeMode;
m_nSystemButtonsNumSaved = m_nSystemButtonsNum;
SetMaximizeMode (FALSE);
}
else
{
if (m_bActualMaximizeMode)
{
RestoreMaximizeMode ();
}
}
CBCGToolBar::OnCustomizeMode (bSet);
}
//****************************************************************************************
BOOL CBCGMenuBar::RestoreOriginalstate ()
{
ASSERT (m_hMenu != NULL);
HMENU hMenuCurr = m_hMenu;
g_menuHash.SaveMenuBar (m_hMenu, this);
BOOL bCurrMenuIsRestored = FALSE;
//------------------------------------------------------------
// Save current maximize mode (system buttons are not saved!):
//------------------------------------------------------------
BOOL bMaximizeMode = m_bMaximizeMode;
SetMaximizeMode (FALSE);
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (pDocManager != NULL)
{
//---------------------------------------
// Walk all templates in the application:
//---------------------------------------
for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
{
CBCGMultiDocTemplate* pTemplate =
(CBCGMultiDocTemplate*) pDocManager->GetNextDocTemplate (pos);
ASSERT_VALID (pTemplate);
ASSERT_KINDOF (CDocTemplate, pTemplate);
//-----------------------------------------------------
// We are interessing CMultiDocTemplate objects with
// the shared menu only....
//-----------------------------------------------------
if (!pTemplate->IsKindOf (RUNTIME_CLASS (CMultiDocTemplate)) ||
pTemplate->m_hMenuShared == NULL)
{
continue;
}
UINT uiMenuResId = pTemplate->GetResId ();
ASSERT (uiMenuResId != 0);
//-------------------------------------
// Restore original menu from resource:
//-------------------------------------
HINSTANCE hInst = AfxFindResourceHandle (
MAKEINTRESOURCE (uiMenuResId), RT_MENU);
BOOL bCurr = (hMenuCurr == pTemplate->m_hMenuShared);
pTemplate->m_hMenuShared = ::LoadMenu (hInst, MAKEINTRESOURCE (uiMenuResId));
CreateFromMenu (pTemplate->m_hMenuShared, FALSE);
g_menuHash.SaveMenuBar (pTemplate->m_hMenuShared, this);
if (bCurr)
{
hMenuCurr = pTemplate->m_hMenuShared;
bCurrMenuIsRestored = TRUE;
}
}
}
//----------------------
// Load defualt menubar:
//----------------------
if (m_uiDefMenuResId != 0)
{
HINSTANCE hInst = AfxFindResourceHandle (
MAKEINTRESOURCE (m_uiDefMenuResId), RT_MENU);
m_hDefaultMenu = ::LoadMenu (hInst, MAKEINTRESOURCE (m_uiDefMenuResId));
OnDefaultMenuLoaded(m_hDefaultMenu);
CreateFromMenu (m_hDefaultMenu, TRUE);
g_menuHash.SaveMenuBar (m_hDefaultMenu, this);
if (!bCurrMenuIsRestored)
{
hMenuCurr = m_hDefaultMenu;
}
}
//----------------------
// Restore current menu:
//----------------------
if (bMaximizeMode)
{
RestoreMaximizeMode ();
}
if (g_menuHash.LoadMenuBar (hMenuCurr, this))
{
m_hMenu = hMenuCurr;
GetParentFrame ()->RecalcLayout ();
Invalidate ();
UpdateWindow ();
}
return TRUE;
}
//********************************************************************************************
void CBCGMenuBar::SetDefaultMenuResId (UINT uiResId)
{
m_uiDefMenuResId = uiResId;
}
//******************************************************************
BOOL CBCGMenuBar::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
//-----------------------------------------------------------
// Fisrt, try to move keyboard control to the drop-down menu:
//-----------------------------------------------------------
CBCGToolbarMenuButton* pMenuButon = GetDroppedDownMenu ();
if (pMenuButon != NULL)
{
return CControlBar::PreTranslateMessage(pMsg);
}
int iTotalItems = GetCount ();
if (m_bMaximizeMode)
{
iTotalItems -= m_nSystemButtonsNum;
}
if (m_iHighlighted >= 0 && m_iHighlighted < iTotalItems)
{
int iButton = m_iHighlighted;
switch (pMsg->wParam)
{
case VK_ESCAPE:
{
Deactivate ();
RestoreFocus ();
m_bShowAllCommands = FALSE;
}
break;
case VK_RIGHT:
if (++ m_iHighlighted >= iTotalItems)
{
m_iHighlighted = 0;
}
InvalidateButton (iButton);
InvalidateButton (m_iHighlighted);
UpdateWindow ();
break;
case VK_LEFT:
if (-- m_iHighlighted < 0)
{
m_iHighlighted = iTotalItems - 1;
}
InvalidateButton (iButton);
InvalidateButton (m_iHighlighted);
UpdateWindow ();
break;
case VK_DOWN:
DropDownMenu (GetButton (m_iHighlighted));
return TRUE;
case VK_RETURN:
if (!DropDownMenu (GetButton (m_iHighlighted)))
{
ProcessCommand (GetButton (m_iHighlighted));
}
return TRUE;
default:
if (TranslateChar ((int) pMsg->wParam))
{
return TRUE;
}
}
}
}
return CControlBar::PreTranslateMessage(pMsg);
}
//**************************************************************************************
void CBCGMenuBar::OnKillFocus(CWnd* pNewWnd)
{
CBCGToolBar::OnKillFocus(pNewWnd);
if (!IsCustomizeMode ())
{
CBCGPopupMenu* pMenu = DYNAMIC_DOWNCAST (CBCGPopupMenu, pNewWnd);
if (pMenu == NULL || pMenu->GetParentToolBar () != this)
{
Deactivate ();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?