📄 bcgptoolbarcustomize.cpp
字号:
//-------------------------------------------
// Add a new button to the specific category:
//-------------------------------------------
BOOL bInserted = FALSE;
if (iInsertAfter != -1)
{
POSITION pos = pCategoryButtonsList->FindIndex (iInsertAfter);
if (pos != NULL)
{
pCategoryButtonsList->InsertBefore (pos, pButton);
bInserted = TRUE;
}
}
if (!bInserted)
{
pCategoryButtonsList->AddTail (pButton);
}
if (lpszCategory != m_strAllCommands)
{
AddButton (m_strAllCommands, button);
}
pButton->OnAddToCustomizePage ();
}
//**************************************************************************************
int CBCGPToolbarCustomize::RemoveButton (UINT uiCategoryId, UINT uiCmdId)
{
if (uiCategoryId == (UINT) -1) // Remove from ALL caregories
{
BOOL bFinish = FALSE;
for (POSITION posCategory = m_strCategoriesList.GetHeadPosition();
!bFinish;)
{
CString strCategory;
if (posCategory == NULL)
{
strCategory = m_strAllCommands;
bFinish = TRUE;
}
else
{
strCategory = m_strCategoriesList.GetNext (posCategory);
}
RemoveButton (strCategory, uiCmdId);
}
return 0;
}
CString strCategory;
strCategory.LoadString (uiCategoryId);
return RemoveButton (strCategory, uiCmdId);
}
//**************************************************************************************
int CBCGPToolbarCustomize::RemoveButton (LPCTSTR lpszCategory, UINT uiCmdId)
{
ASSERT (lpszCategory != NULL);
CObList* pCategoryButtonsList;
if (!m_ButtonsByCategory.Lookup (lpszCategory, pCategoryButtonsList))
{
// Category not found!
return -1;
}
int i = 0;
for (POSITION pos = pCategoryButtonsList->GetHeadPosition (); pos != NULL; i ++)
{
POSITION posSave = pos;
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nID == uiCmdId)
{
pCategoryButtonsList->RemoveAt (posSave);
delete pButton;
return i;
}
}
return -1;
}
//**************************************************************************************
BOOL CBCGPToolbarCustomize::AddToolBar (UINT uiCategory, UINT uiToolbarResId)
{
CString strCategory;
strCategory.LoadString (uiCategory);
return AddToolBar (strCategory, uiToolbarResId);
}
//**************************************************************************************
BOOL CBCGPToolbarCustomize::AddToolBar (LPCTSTR lpszCategory, UINT uiToolbarResId)
{
struct CToolBarData
{
WORD wVersion;
WORD wWidth;
WORD wHeight;
WORD wItemCount;
WORD* items()
{ return (WORD*)(this+1); }
};
LPCTSTR lpszResourceName = MAKEINTRESOURCE (uiToolbarResId);
ASSERT(lpszResourceName != NULL);
//---------------------------------------------------
// determine location of the bitmap in resource fork:
//---------------------------------------------------
HINSTANCE hInst = AfxFindResourceHandle(lpszResourceName, RT_TOOLBAR);
HRSRC hRsrc = ::FindResource(hInst, lpszResourceName, RT_TOOLBAR);
if (hRsrc == NULL)
{
TRACE(_T("CBCGPToolbarCustomize::AddToolBar: Can't load toolbar %x\n"), uiToolbarResId);
return FALSE;
}
HGLOBAL hGlobal = ::LoadResource(hInst, hRsrc);
if (hGlobal == NULL)
{
TRACE(_T("CBCGPToolbarCustomize::AddToolBar: Can't load toolbar %x\n"), uiToolbarResId);
return FALSE;
}
CToolBarData* pData = (CToolBarData*)LockResource(hGlobal);
if (pData == NULL)
{
TRACE(_T("CBCGPToolbarCustomize::AddToolBar: Can't load toolbar %x\n"), uiToolbarResId);
::FreeResource (hGlobal);
return FALSE;
}
ASSERT (pData->wVersion == 1);
for (int i = 0; i < pData->wItemCount; i++)
{
UINT uiCmd = pData->items() [i];
if (uiCmd > 0 && uiCmd != (UINT) -1)
{
AddButton (lpszCategory, CBCGPToolbarButton (uiCmd, -1));
}
}
::UnlockResource (hGlobal);
::FreeResource (hGlobal);
return TRUE;
}
//**************************************************************************************
BOOL CBCGPToolbarCustomize::AddMenu (UINT uiMenuResId)
{
CMenu menu;
if (!menu.LoadMenu (uiMenuResId))
{
TRACE(_T("CBCGPToolbarCustomize::AddMenu: Can't load menu %x\n"), uiMenuResId);
return FALSE;
}
AddMenuCommands (&menu, FALSE);
return TRUE;
}
//**************************************************************************************
//ET: Rename automatically imported categories (e.g. "?"->"Help")
BOOL CBCGPToolbarCustomize::RenameCategory(LPCTSTR lpszCategoryOld, LPCTSTR lpszCategoryNew)
{
// New Name must not be present
POSITION pos = m_strCategoriesList.Find(lpszCategoryNew);
if(pos)
return FALSE;
// ...but the old one must be
pos = m_strCategoriesList.Find(lpszCategoryOld);
if(!pos)
return FALSE;
// Change Name in Button-map too:
CObList* pCategoryButtonsList;
// new Category must not be present yet
if (m_ButtonsByCategory.Lookup (lpszCategoryNew, pCategoryButtonsList))
return FALSE;
// ...but the old one must be
if (!m_ButtonsByCategory.Lookup (lpszCategoryOld, pCategoryButtonsList))
return FALSE;
// change both or nothing
m_strCategoriesList.SetAt(pos, lpszCategoryNew);
m_ButtonsByCategory.RemoveKey(lpszCategoryOld);
m_ButtonsByCategory.SetAt(lpszCategoryNew, pCategoryButtonsList);
return TRUE;
}
//**************************************************************************************
void CBCGPToolbarCustomize::ReplaceButton (UINT uiCmd, const CBCGPToolbarButton& button)
{
CRuntimeClass* pClass = button.GetRuntimeClass ();
ASSERT (pClass != NULL);
BOOL bFinish = FALSE;
for (POSITION posCategory = m_strCategoriesList.GetHeadPosition();
!bFinish;)
{
CString strCategory;
if (posCategory == NULL)
{
strCategory = m_strAllCommands;
bFinish = TRUE;
}
else
{
strCategory = m_strCategoriesList.GetNext (posCategory);
}
CObList* pCategoryButtonsList;
if (!m_ButtonsByCategory.Lookup (strCategory, pCategoryButtonsList))
{
ASSERT (FALSE);
}
ASSERT_VALID (pCategoryButtonsList);
for (POSITION pos = pCategoryButtonsList->GetHeadPosition (); pos != NULL;)
{
POSITION posSave = pos;
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nID == uiCmd) // Found!
{
CBCGPToolbarButton* pNewButton = (CBCGPToolbarButton*) pClass->CreateObject ();
ASSERT_VALID (pNewButton);
pNewButton->CopyFrom (button);
if (pNewButton->m_strText.IsEmpty ())
{
pNewButton->m_strText = pButton->m_strText;
}
pCategoryButtonsList->SetAt (posSave, pNewButton);
delete pButton;
}
}
}
}
//**************************************************************************************
BOOL CBCGPToolbarCustomize::SetUserCategory (LPCTSTR lpszCategory)
{
ASSERT (lpszCategory != NULL);
CObList* pCategoryButtonsList;
if (!m_ButtonsByCategory.Lookup (lpszCategory, pCategoryButtonsList))
{
TRACE(_T("CBCGPToolbarCustomize::SetUserCategory: Can't find category '%s'\n"),
lpszCategory);
return FALSE;
}
m_pCustomizePage->SetUserCategory (lpszCategory);
return TRUE;
}
//**************************************************************************************
void CBCGPToolbarCustomize::SetFrameCustMode (BOOL bCustMode)
{
ASSERT_VALID (m_pParentFrame);
//-------------------------------------------------------------------
// Enable/disable all parent frame child windows (except docking bars
// and our toolbars):
//-------------------------------------------------------------------
CWnd* pWndChild = m_pParentFrame->GetWindow (GW_CHILD);
while (pWndChild != NULL)
{
CRuntimeClass* pChildClass = pWndChild->GetRuntimeClass ();
if (pChildClass == NULL ||
(!pChildClass->IsDerivedFrom (RUNTIME_CLASS (CDockBar)) &&
!pChildClass->IsDerivedFrom (RUNTIME_CLASS (CBCGPDockBar)) &&
!pChildClass->IsDerivedFrom (RUNTIME_CLASS (CBCGPOutlookBar)) &&
#ifndef BCG_NO_REBAR
!pChildClass->IsDerivedFrom (RUNTIME_CLASS (CBCGPReBar)) &&
#endif // BCG_NO_REBAR
!pChildClass->IsDerivedFrom (RUNTIME_CLASS (CBCGPToolBar))))
{
pWndChild->EnableWindow (!bCustMode);
}
pWndChild = pWndChild->GetNextWindow ();
}
//-----------------------------------------------
// Set/reset costumize mode for ALL our toolbars:
//-----------------------------------------------
CBCGPToolBar::SetCustomizeMode (bCustMode);
//-------------------------------------------------------------
// Inform the parent frame about mode (for additional actions):
//-------------------------------------------------------------
m_pParentFrame->SendMessage (BCGM_CUSTOMIZETOOLBAR, (WPARAM) bCustMode);
if (!bCustMode && m_pParentFrame->GetActiveFrame () != NULL)
{
//---------------------
// Restore active view:
//---------------------
m_pParentFrame->GetActiveFrame ()->PostMessage (WM_SETFOCUS);
}
}
//**************************************************************************************
BOOL CBCGPToolbarCustomize::Create ()
{
{
CBCGPLocalResource locaRes;
if (!CPropertySheet::Create (m_pParentFrame))
{
return FALSE;
}
}
SetFrameCustMode (TRUE);
return TRUE;
}
//*************************************************************************************
void CBCGPToolbarCustomize::ShowToolBar (CBCGPToolBar* pToolBar, BOOL bShow)
{
m_pToolbarsPage->ShowToolBar (pToolBar, bShow);
}
//*************************************************************************************
BOOL CBCGPToolbarCustomize::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
CRect rectClient; // Client area rectangle
GetClientRect (&rectClient);
//----------------------
// Show "Cancel" button:
//----------------------
CWnd *pWndCancel = GetDlgItem (IDCANCEL);
if (pWndCancel == NULL)
{
return bResult;
}
pWndCancel->ShowWindow (SW_SHOW);
pWndCancel->EnableWindow ();
CRect rectClientCancel;
pWndCancel->GetClientRect (&rectClientCancel);
pWndCancel->MapWindowPoints (this, &rectClientCancel);
//-------------------------------
// Enlarge property sheet window:
//-------------------------------
CRect rectWnd;
GetWindowRect(rectWnd);
SetWindowPos(NULL, 0, 0,
rectWnd.Width (),
rectWnd.Height () + rectClientCancel.Height () + 2 * iButtonMargin,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
//-------------------------------------------------
// Move "Cancel" button to the right bottom corner:
//-------------------------------------------------
pWndCancel->SetWindowPos (NULL,
rectClient.right - rectClientCancel.Width () - iButtonMargin,
rectClientCancel.top + iButtonMargin / 2,
0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
//---------------------------------------------------
// Change "Cancel" button's style to "DEFPUSHBUTTON":
//---------------------------------------------------
CWnd *pWndOk = GetDlgItem (IDOK);
if (pWndOk != NULL)
{
pWndOk->ModifyStyle (BS_DEFPUSHBUTTON, 0);
}
pWndCancel->ModifyStyle (0, BS_DEFPUSHBUTTON);
//--------------------------------------------------------
// Replace "Cancel" text to "Close"
// (CPropertyPage::CancelToClose method does nothing in a
// modeless property sheet):
//--------------------------------------------------------
CString strCloseText;
{
CBCGPLocalResource locaRes;
strCloseText.LoadString (IDS_BCGBARRES_CLOSE);
}
pWndCancel->SetWindowText (strCloseText);
//------------------------
// Adjust the Help button:
//------------------------
CButton *pWndHelp = (CButton*) GetDlgItem (IDHELP);
if (pWndHelp == NULL)
{
return bResult;
}
if (m_uiFlags & BCGCUSTOMIZE_NOHELP)
{
pWndHelp->ShowWindow (SW_HIDE);
pWndHelp->EnableWindow(FALSE);
}
else
{
pWndHelp->ShowWindow (SW_SHOW);
pWndHelp->EnableWindow ();
//-----------------------
// Set Help button image:
//-----------------------
CBCGPLocalResource locaRes;
LPCTSTR lpszResourceName = MAKEINTRESOURCE (IDB_BCGBARRES_HELP);
ASSERT(lpszResourceName != NULL);
HBITMAP hbmpHelp = (HBITMAP) ::LoadImage (
AfxFindResourceHandle (lpszResourceName, RT_BITMAP),
lpszResourceName,
IMAGE_BITMAP,
0, 0,
LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS);
ASSERT (hbmpHelp != NULL);
pWndHelp->ModifyStyle (0, BS_BITMAP);
pWndHelp->SetBitmap (hbmpHelp);
//-------------------------------------------------
// Move "Help" button to the left bottom corner and
// adjust its size by the bitmap size:
//-------------------------------------------------
BITMAP bmp;
::GetObject (hbmpHelp, sizeof (BITMAP), &bmp);
pWndHelp->SetWindowPos (NULL,
rectClient.left + iButtonMargin,
rectClientCancel.top,
bmp.bmWidth + iButtonMargin, bmp.bmHeight + iButtonMargin,
SWP_NOZORDER | SWP_NOACTIVATE);
}
return bResult;
}
//************************************************************************************
BOOL CBCGPToolbarCustomize::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch (LOWORD (wParam))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -