📄 customizepropsheet.cpp
字号:
#include "stdafx.h"
#include "afxpriv.h"
#include "bcgbarres.h"
#include "CustomizePropSheet.h"
#include "BCGToolBar.h"
#include "BCGMenuBar.h"
#include "bcglocalres.h"
#include "BCGMouseManager.h"
#include "BCGContextMenuManager.h"
#include "ButtonsTextList.h"
#include "BCGMDIFrameWnd.h"
#include "BCGFrameWnd.h"
#include "BCGKeyboardManager.h"
#include "BCGToolbarMenuButton.h"
#include "BCGDockBar.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
//CBCGToolbarCustomize* g_pWndCustomize = NULL;
static const int iButtonMargin = 8;
/////////////////////////////////////////////////////////////////////////////
// CBCGToolbarCustomize
IMPLEMENT_DYNAMIC(CCustomizePropSheet, CPropertySheet)
CCustomizePropSheet::CCustomizePropSheet(
CFrameWnd* pWndParentFrame,
BOOL bAutoSetFromMenus /* = FALSE */,
UINT uiFlags /* = 0xFFFF */,
CList<CRuntimeClass*,CRuntimeClass*>* m_plistCustomPages /* = NULL */)
: CPropertySheet(_T(""), pWndParentFrame),
m_bAutoSetFromMenus (bAutoSetFromMenus),
m_uiFlags (uiFlags)
{
//-------------------------------
// ET: Add optional custom pages:
//-------------------------------
/* if(m_plistCustomPages != NULL) {
// does not use lib local resources, so moved to front
ASSERT_VALID(m_plistCustomPages);
for(POSITION pos=m_plistCustomPages->GetHeadPosition(); pos; )
{
CRuntimeClass* pClass = m_plistCustomPages->GetNext(pos);
m_listCustomPages.AddTail( (CPropertyPage*) pClass->CreateObject() );
}
}
CBCGLocalResource locaRes;
ASSERT (pWndParentFrame != NULL);
m_pParentFrame = pWndParentFrame;
m_pCustomizePage = new CBCGCustomizePage;
m_pToolbarsPage = new CBCGToolbarsPage (m_pParentFrame);
m_pKeyboardPage = new CBCGKeyboardPage (m_pParentFrame, m_bAutoSetFromMenus);
m_pMenuPage = new CBCGMenuPage (m_bAutoSetFromMenus);
m_pMousePage = new CBCGMousePage;
//---------------------------------------
// Add two main pages (available always):
//---------------------------------------
AddPage (m_pCustomizePage);
AddPage (m_pToolbarsPage);
//---------------------------------------------------------
// Add keyboard customization page (available only if
// the main application windows accelerator table is exist):
//---------------------------------------------------------
if (g_pKeyboardManager != NULL && pWndParentFrame->m_hAccelTable != NULL)
{
AddPage (m_pKeyboardPage);
}
//---------------------------------------------------------------
// Add menu customization page (available only if the menu bar or
// context menu manager are available):
//---------------------------------------------------------------
BOOL bMenuBarIsAvailable = FALSE;
CBCGMDIFrameWnd* pMainMDIFrame = DYNAMIC_DOWNCAST (CBCGMDIFrameWnd, m_pParentFrame);
if (pMainMDIFrame != NULL)
{
bMenuBarIsAvailable = (pMainMDIFrame->IsMenuBarAvailable ());
}
else
{
CBCGFrameWnd* pMainFrame = DYNAMIC_DOWNCAST (CBCGFrameWnd, m_pParentFrame);
if (pMainFrame != NULL)
{
bMenuBarIsAvailable = (pMainFrame->IsMenuBarAvailable ());
}
}
if (g_pContextMenuManager != NULL || bMenuBarIsAvailable)
{
AddPage (m_pMenuPage);
}
if (g_pMouseManager != NULL)
{
AddPage (m_pMousePage);
}
//-------------------------------
// ET: Add optional custom pages:
//-------------------------------
for(POSITION pos=m_listCustomPages.GetHeadPosition(); pos; )
{
AddPage( m_listCustomPages.GetNext(pos) );
}
m_pOptionsPage = new CBCGOptionsPage (bMenuBarIsAvailable);
AddPage (m_pOptionsPage);
//----------------------------
// Set property sheet caption:
//----------------------------
CString strCaption;
strCaption.LoadString (IDS_BCGBARRES_PROPSHT_CAPTION);
m_strAllCommands.LoadString (IDS_BCGBARRES_ALL_COMMANDS);
m_pCustomizePage->SetAllCategory (m_strAllCommands);
SetTitle (strCaption);
if (m_bAutoSetFromMenus)
{
SetupFromMenus ();
}
//-------------------------
// Add a "New menu" button:
//-------------------------
CString strNewMenu;
strNewMenu.LoadString (IDS_BCGBARRES_NEW_MENU);
AddButton (strNewMenu, CBCGToolbarMenuButton (0, NULL, -1, strNewMenu));
*/
}
//**************************************************************************************
CCustomizePropSheet::~CCustomizePropSheet()
{
/*POSITION pos = m_ButtonsByCategory.GetStartPosition();
while (pos != NULL)
{
CObList* pCategoryButtonsList;
CString string;
m_ButtonsByCategory.GetNextAssoc (pos, string, pCategoryButtonsList);
ASSERT_VALID(pCategoryButtonsList);
while (!pCategoryButtonsList->IsEmpty ())
{
delete pCategoryButtonsList->RemoveHead ();
}
delete pCategoryButtonsList;
}
m_ButtonsByCategory.RemoveAll();
delete m_pCustomizePage;
delete m_pToolbarsPage;
delete m_pKeyboardPage;
delete m_pMenuPage;
delete m_pMousePage;
delete m_pOptionsPage;
//--------------------------------------
// ET: delete all optional custom pages:
//--------------------------------------
while(!m_listCustomPages.IsEmpty())
{
delete m_listCustomPages.RemoveHead();
}*/
}
BEGIN_MESSAGE_MAP(CCustomizePropSheet, CPropertySheet)
//{{AFX_MSG_MAP(CBCGToolbarCustomize)
ON_WM_CREATE()
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCGToolbarCustomize message handlers
int CCustomizePropSheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
/* if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
{
return -1;
}
g_pWndCustomize = this;
SetFrameCustMode (TRUE);*/
return 0;
}
//**************************************************************************************
void CCustomizePropSheet::PostNcDestroy()
{
/* g_pWndCustomize = NULL;
SetFrameCustMode (FALSE);
CPropertySheet::PostNcDestroy();
delete this;*/
}
//**************************************************************************************
void CCustomizePropSheet::AddButton (UINT uiCategoryId, const CBCGToolbarButton& button,
int iInsertAfter)
{
/* CString strCategory;
strCategory.LoadString (uiCategoryId);
AddButton (strCategory, button, iInsertAfter);*/
}
//**************************************************************************************
void CCustomizePropSheet::AddButton (LPCTSTR lpszCategory, const CBCGToolbarButton& button,
int iInsertAfter)
{
/*int iId = (int) button.m_nID;
if (IsStandardCommand (iId))
{
//-------------------------------------------
// Don't add MRU, system and Window commands:
//-------------------------------------------
return;
}
if (!CBCGToolBar::IsCommandPermitted (button.m_nID))
{
return;
}
CString strText = button.m_strText;
strText.TrimLeft ();
strText.TrimRight ();
if (strText.IsEmpty ())
{
//-------------------------------------------
// Try to find the command name in resources:
//-------------------------------------------
CString strMessage;
int iOffset;
if (strMessage.LoadString (button.m_nID) &&
(iOffset = strMessage.Find (_T('\n'))) != -1)
{
strText = strMessage.Mid (iOffset + 1);
}
if (strText.IsEmpty () && lpszCategory == m_strAllCommands)
{
return;
}
}
else
{
strText.Remove (_T('&'));
//----------------------------------------
// Remove trailing label (ex.:"\tCtrl+S"):
//----------------------------------------
int iOffset = strText.Find (_T('\t'));
if (iOffset != -1)
{
strText = strText.Left (iOffset);
}
}
//---------------------------------------------------------------
// If text is still empty, assume dummy command and don't add it:
//---------------------------------------------------------------
if (strText.IsEmpty ())
{
return;
}
//--------------------------------------------------
// Find a category entry or create new if not exist:
//--------------------------------------------------
CObList* pCategoryButtonsList;
if (!m_ButtonsByCategory.Lookup (lpszCategory, pCategoryButtonsList))
{
//--------------------------------
// Category not found! Create new:
//--------------------------------
pCategoryButtonsList = new CObList;
m_ButtonsByCategory.SetAt (lpszCategory, pCategoryButtonsList);
if (lpszCategory != m_strAllCommands)
{
m_strCategoriesList.AddTail (lpszCategory);
}
}
else
{
//--------------------------------------------------------
// Category is not a new. Maybe the button is exist also?
//--------------------------------------------------------
ASSERT (pCategoryButtonsList != NULL);
for (POSITION pos = pCategoryButtonsList->GetHeadPosition (); pos != NULL;)
{
CBCGToolbarButton* pButton = (CBCGToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
// Fixed by Eberhard Beilharz:
if ((pButton->m_nID == button.m_nID && pButton->m_nID != -1)
|| (pButton->m_nID == -1 && pButton->m_strText == button.m_strText))
// The same exist...
{
if (pButton->m_strText.IsEmpty ())
{
pButton->m_strText = button.m_strText;
}
return;
}
}
}
//-------------------------------------------------------------------
// Create a new CBCGToolbarButton object (MFC class factory is used):
//-------------------------------------------------------------------
CRuntimeClass* pClass = button.GetRuntimeClass ();
ASSERT (pClass != NULL);
CBCGToolbarButton* pButton = (CBCGToolbarButton*) pClass->CreateObject ();
ASSERT_VALID (pButton);
pButton->CopyFrom (button);
pButton->m_strText = strText;
//-------------------------------------------
// 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 CCustomizePropSheet::RemoveButton (UINT uiCategoryId, UINT uiCmdId)
{
// CString strCategory;
// strCategory.LoadString (uiCategoryId);
return 1;//RemoveButton (strCategory, uiCmdId);
}
//**************************************************************************************
int CCustomizePropSheet::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;
CBCGToolbarButton* pButton = (CBCGToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nID == uiCmdId)
{
pCategoryButtonsList->RemoveAt (posSave);
delete pButton;
return i;
}
}*/
return -1;
}
//**************************************************************************************
BOOL CCustomizePropSheet::AddToolBar (UINT uiCategory, UINT uiToolbarResId)
{
// CString strCategory;
// strCategory.LoadString (uiCategory);
return 1;//AddToolBar (strCategory, uiToolbarResId);
}
//**************************************************************************************
BOOL CCustomizePropSheet::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("CBCGToolbarCustomize::AddToolBar: Can't load toolbar %x\n"), uiToolbarResId);
return FALSE;
}
HGLOBAL hGlobal = ::LoadResource(hInst, hRsrc);
if (hGlobal == NULL)
{
TRACE(_T("CBCGToolbarCustomize::AddToolBar: Can't load toolbar %x\n"), uiToolbarResId);
return FALSE;
}
CToolBarData* pData = (CToolBarData*)LockResource(hGlobal);
if (pData == NULL)
{
TRACE(_T("CBCGToolbarCustomize::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, CBCGToolbarButton (uiCmd, -1));
}
}
::UnlockResource (hGlobal);
::FreeResource (hGlobal);*/
return TRUE;
}
//**************************************************************************************
BOOL CCustomizePropSheet::AddMenu (UINT uiMenuResId)
{
/*CMenu menu;
if (!menu.LoadMenu (uiMenuResId))
{
TRACE(_T("CBCGToolbarCustomize::AddMenu: Can't load menu %x\n"), uiMenuResId);
return FALSE;
}
AddMenuCommands (&menu, FALSE);*/
return TRUE;
}
//**************************************************************************************
//ET: Rename automatically imported categories (e.g. "?"->"Help")
BOOL CCustomizePropSheet::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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -