📄 bcgptoolbarcustomize.cpp
字号:
{
case IDCANCEL:
if (g_pUserToolsManager != NULL && m_pToolsPage != NULL)
{
if (!CheckToolsValidity (g_pUserToolsManager->GetUserTools ()))
{
// Continue customization....
if (GetActivePage () != m_pToolsPage)
{
SetActivePage (m_pToolsPage);
}
return TRUE;
}
}
DestroyWindow ();
return TRUE;
case IDHELP:
ASSERT_VALID (m_pParentFrame);
m_pParentFrame->SendMessage (BCGM_CUSTOMIZEHELP, GetActiveIndex (), (LPARAM) this);
return TRUE;
}
return CPropertySheet::OnCommand(wParam, lParam);
}
//************************************************************************************
void CBCGPToolbarCustomize::EnableUserDefinedToolbars (BOOL bEnable)
{
m_pToolbarsPage->EnableUserDefinedToolbars (bEnable);
}
//******************************************************************************************
void CBCGPToolbarCustomize::AddMenuCommands (const CMenu* pMenu, BOOL bPopup,
LPCTSTR lpszCategory, LPCTSTR lpszMenuPath)
{
ASSERT (pMenu != NULL);
BOOL bIsWindowsMenu = FALSE;
int iCount = (int) pMenu->GetMenuItemCount ();
for (int i = 0; i < iCount; i ++)
{
UINT uiCmd = pMenu->GetMenuItemID (i);
CString strText;
pMenu->GetMenuString (i, strText, MF_BYPOSITION);
if(!m_bSaveMenuAmps)
{
strText.Remove (_T('&'));
}
switch (uiCmd)
{
case 0: // Separator, ignore it.
break;
case -1: // Submenu
{
CMenu* pSubMenu = pMenu->GetSubMenu (i);
UINT uiTearOffId = 0;
if (g_pTearOffMenuManager != NULL)
{
uiTearOffId = g_pTearOffMenuManager->Parse (strText);
}
CString strCategory = strText;
strCategory.Remove (_T('&'));
if (lpszCategory != NULL)
{
strCategory = lpszCategory;
}
if (m_bAutoSetFromMenus)
{
if (bPopup)
{
CBCGPToolbarMenuButton menuButton ((UINT) -1,
pSubMenu->GetSafeHmenu (),
-1,
strText);
menuButton.SetTearOff (uiTearOffId);
AddButton (strCategory, menuButton);
}
CString strPath;
if (lpszMenuPath != NULL)
{
strPath = lpszMenuPath;
}
strPath += strText;
AddMenuCommands (pSubMenu, bPopup, strCategory, strPath);
}
else
{
AddMenuCommands (pSubMenu, bPopup);
}
}
break;
default:
if (bPopup && uiCmd >= AFX_IDM_WINDOW_FIRST && uiCmd <= AFX_IDM_WINDOW_LAST)
{
bIsWindowsMenu = TRUE;
}
if (lpszCategory != NULL &&
g_pUserToolsManager != NULL &&
g_pUserToolsManager->GetToolsEntryCmd () == uiCmd)
{
//----------------------------------------------
// Replace tools entry by the actual tools list:
//----------------------------------------------
AddUserTools (lpszCategory);
}
else
{
CBCGPToolbarButton button (uiCmd, -1, strText);
if (lpszMenuPath != NULL)
{
CString strCustom = CString (lpszMenuPath) + button.m_strText;
LPTSTR pszCustom = strCustom.GetBuffer (strCustom.GetLength () + 1);
for (int iCount = 0; iCount < lstrlen (pszCustom) - 1; iCount++)
{
if (pszCustom [iCount] == _TCHAR(' '))
{
CharUpperBuff (&pszCustom [iCount + 1], 1);
}
}
strCustom.ReleaseBuffer();
strCustom.Remove (_T(' '));
button.m_strTextCustom = strCustom.SpanExcluding (_T("\t"));
}
AddButton (lpszCategory == NULL ?
m_strAllCommands : lpszCategory,
button);
}
}
}
//--------------------------
// Add windows manager item:
//--------------------------
if (bIsWindowsMenu && lpszCategory != NULL)
{
CBCGPMDIFrameWnd* pMainMDIFrame = DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, m_pParentFrame);
if (pMainMDIFrame != NULL &&
pMainMDIFrame->m_uiWindowsDlgMenuId != 0 &&
pMainMDIFrame->m_bShowWindowsDlgAlways)
{
AddButton (lpszCategory,
CBCGPToolbarButton (pMainMDIFrame->m_uiWindowsDlgMenuId, -1,
pMainMDIFrame->m_strWindowsDlgMenuText));
}
}
}
//******************************************************************************************
void CBCGPToolbarCustomize::FillCategoriesComboBox (CComboBox& wndCategory,
BOOL bAddEmpty) const
{
CObList* pCategoryButtonsList;
for (POSITION pos = m_strCategoriesList.GetHeadPosition(); pos != NULL;)
{
CString strCategory = m_strCategoriesList.GetNext (pos);
if (!m_ButtonsByCategory.Lookup (strCategory, pCategoryButtonsList))
{
ASSERT (FALSE);
}
ASSERT_VALID (pCategoryButtonsList);
BOOL bIsEmpty = FALSE;
if (!bAddEmpty)
{
bIsEmpty = TRUE;
for (POSITION posCat = pCategoryButtonsList->GetHeadPosition (); posCat != NULL;)
{
CBCGPToolbarButton* pButton =
(CBCGPToolbarButton*) pCategoryButtonsList->GetNext (posCat);
ASSERT_VALID (pButton);
if (pButton->m_nID > 0 && pButton->m_nID != (UINT) -1)
{
bIsEmpty = FALSE;
break;
}
}
}
if (!bIsEmpty)
{
int iIndex = wndCategory.AddString (strCategory);
wndCategory.SetItemData (iIndex, (DWORD) pCategoryButtonsList);
}
}
// "All" category should be last!
if (!m_ButtonsByCategory.Lookup (m_strAllCommands, pCategoryButtonsList))
{
ASSERT (FALSE);
}
ASSERT_VALID (pCategoryButtonsList);
int iIndex = wndCategory.AddString (m_strAllCommands);
wndCategory.SetItemData (iIndex, (DWORD) pCategoryButtonsList);
}
//******************************************************************************************
void CBCGPToolbarCustomize::FillCategoriesListBox (CListBox& wndCategory,
BOOL bAddEmpty) const
{
CObList* pCategoryButtonsList;
for (POSITION pos = m_strCategoriesList.GetHeadPosition(); pos != NULL;)
{
CString strCategory = m_strCategoriesList.GetNext (pos);
if (!m_ButtonsByCategory.Lookup (strCategory, pCategoryButtonsList))
{
ASSERT (FALSE);
}
ASSERT_VALID (pCategoryButtonsList);
BOOL bIsEmpty = FALSE;
if (!bAddEmpty)
{
bIsEmpty = TRUE;
for (POSITION posCat = pCategoryButtonsList->GetHeadPosition (); posCat != NULL;)
{
CBCGPToolbarButton* pButton =
(CBCGPToolbarButton*) pCategoryButtonsList->GetNext (posCat);
ASSERT_VALID (pButton);
if (pButton->m_nID > 0 && pButton->m_nID != (UINT) -1)
{
bIsEmpty = FALSE;
break;
}
}
}
if (!bIsEmpty)
{
int iIndex = wndCategory.AddString (strCategory);
wndCategory.SetItemData (iIndex, (DWORD) pCategoryButtonsList);
}
}
// "All" category should be last!
if (!m_ButtonsByCategory.Lookup (m_strAllCommands, pCategoryButtonsList))
{
ASSERT (FALSE);
}
ASSERT_VALID (pCategoryButtonsList);
int iIndex = wndCategory.AddString (m_strAllCommands);
wndCategory.SetItemData (iIndex, (DWORD) pCategoryButtonsList);
}
//*******************************************************************************************
void CBCGPToolbarCustomize::FillAllCommandsList (CListBox& wndListOfCommands) const
{
wndListOfCommands.ResetContent ();
CObList* pAllButtonsList;
if (!m_ButtonsByCategory.Lookup (m_strAllCommands, pAllButtonsList))
{
return;
}
ASSERT_VALID (pAllButtonsList);
for (POSITION pos = pAllButtonsList->GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pAllButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
int iIndex = wndListOfCommands.AddString (
pButton->m_strTextCustom.IsEmpty () ? pButton->m_strText : pButton->m_strTextCustom);
wndListOfCommands.SetItemData (iIndex, (DWORD) pButton->m_nID);
}
}
//***************************************************************************************
BOOL CBCGPToolbarCustomize::OnHelpInfo(HELPINFO* pHelpInfo)
{
if ((m_uiFlags & BCGCUSTOMIZE_CONTEXT_HELP) &&
pHelpInfo->iContextType == HELPINFO_WINDOW)
{
pHelpInfo->dwContextId = BCGCBHELP_OFFSET + pHelpInfo->iCtrlId;
AfxGetApp()->WinHelp(pHelpInfo->dwContextId, HELP_CONTEXTPOPUP);
}
else
{
ASSERT_VALID (m_pParentFrame);
m_pParentFrame->SendMessage (BCGM_CUSTOMIZEHELP, GetActiveIndex (),
(LPARAM) this);
}
return TRUE;
}
//***************************************************************************************
LPCTSTR CBCGPToolbarCustomize::GetCommandName (UINT uiCmd) const
{
CObList* pAllButtonsList;
if (!m_ButtonsByCategory.Lookup (m_strAllCommands, pAllButtonsList))
{
return NULL;
}
ASSERT_VALID (pAllButtonsList);
for (POSITION pos = pAllButtonsList->GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pAllButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nID == uiCmd)
{
return pButton->m_strText;
}
}
return NULL;
}
//***************************************************************************************
void CBCGPToolbarCustomize::SetupFromMenus ()
{
//-------------------------------------------------------------------
// Find all application document templates and add menue items to the
// "All commands" category:
//------------------------------------------------------------------
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (pDocManager != NULL)
{
//---------------------------------------
// Walk all templates in the application:
//---------------------------------------
for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
{
CMultiDocTemplate* pTemplate =
DYNAMIC_DOWNCAST ( CMultiDocTemplate,
pDocManager->GetNextDocTemplate (pos));
if (pTemplate != NULL)
{
CMenu* pDocMenu = CMenu::FromHandle (pTemplate->m_hMenuShared);
if (pDocMenu != NULL)
{
AddMenuCommands (pDocMenu, FALSE);
}
}
}
}
//------------------------------------
// Add commands from the default menu:
//------------------------------------
CMenu* pFrameMenu = CMenu::FromHandle (m_pParentFrame->m_hMenuDefault);
if (pFrameMenu == NULL)
{
CBCGPMDIFrameWnd* pMainMDIFrame = DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, m_pParentFrame);
const CBCGPMenuBar* pMenuBar = NULL;
if (pMainMDIFrame != NULL)
{
pMenuBar = pMainMDIFrame->GetMenuBar ();
}
else
{
CBCGPFrameWnd* pMainFrame = DYNAMIC_DOWNCAST (CBCGPFrameWnd, m_pParentFrame);
if (pMainFrame != NULL)
{
pMenuBar = pMainFrame->GetMenuBar ();
}
}
if (pMenuBar != NULL)
{
pFrameMenu = CMenu::FromHandle (pMenuBar->GetDefaultMenu ());
}
}
if (pFrameMenu != NULL)
{
AddMenuCommands (pFrameMenu, FALSE);
}
}
//*****************************************************************************************
void CBCGPToolbarCustomize::AddUserTools (LPCTSTR lpszCategory)
{
ASSERT (lpszCategory != NULL);
ASSERT_VALID (g_pUserToolsManager);
CBCGPLocalResource locaRes;
const CObList& lstTools = g_pUserToolsManager->GetUserTools ();
for (POSITION pos = lstTools.GetHeadPosition (); pos != NULL;)
{
CBCGPUserTool* pTool = (CBCGPUserTool*) lstTools.GetNext (pos);
ASSERT_VALID (pTool);
AddButton (lpszCategory,
CBCGPToolbarButton (pTool->GetCommandId (), 0, pTool->m_strLabel));
}
}
//*******************************************************************************
void CBCGPToolbarCustomize::OnContextMenu(CWnd* pWnd, CPoint /*point*/)
{
if (g_pWorkspace != NULL && (m_uiFlags & BCGCUSTOMIZE_CONTEXT_HELP))
{
g_pWorkspace->OnAppContextHelp (pWnd, dwBCGResHelpIDs);
}
}
//*******************************************************************************
int CBCGPToolbarCustomize::GetCountInCategory (LPCTSTR lpszItemName,
const CObList& lstCommands) const
{
int nCount = 0;
for (POSITION pos = lstCommands.GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) lstCommands.GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_strText == lpszItemName)
{
nCount++;
}
}
return nCount;
}
//********************************************************************************
BOOL CBCGPToolbarCustomize::OnEditToolbarMenuImage (CWnd* pWndParent, CBitmap& bitmap, int nBitsPerPixel)
{
CBCGPImageEditDlg dlg (&bitmap, pWndParent, nBitsPerPixel);
return (dlg.DoModal () == IDOK);
}
#endif // BCG_NO_CUSTOMIZATION
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -