📄 bcgptoolbarcustomize.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a part of the BCGControlBar Library
// Copyright (C) 1998-2000 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions
// of the accompanying license agreement.
//*******************************************************************************
// CBCGPToolbarCustomize.cpp : implementation file
//
#include "stdafx.h"
#ifndef BCG_NO_CUSTOMIZATION
#include "afxpriv.h"
#include "bcgprores.h"
#include "BCGPToolbarCustomize.h"
#include "BCGPToolBar.h"
#include "BCGPMenuBar.h"
#include "BCGPLocalResource.h"
#include "BCGPMouseManager.h"
#include "BCGPContextMenuManager.h"
#include "BCGPTearOffManager.h"
#include "ButtonsTextList.h"
#include "BCGPMDIFrameWnd.h"
#include "BCGPFrameWnd.h"
#include "BCGPKeyboardManager.h"
#include "BCGPUserToolsManager.h"
#include "BCGPToolbarMenuButton.h"
#include "BCGPOutlookBar.h"
#include "BCGPUserTool.h"
#include "BCGPWorkspace.h"
#include "BCGPHelpIds.h"
#include "BCGPVisualManager.h"
#include "BCGPSkinManager.h"
#include "BCGPDockBar.h"
#include "BCGPReBar.h"
#include "ImageEditDlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
CBCGPToolbarCustomize* g_pWndCustomize = NULL;
extern CBCGPWorkspace* g_pWorkspace;
static const int iButtonMargin = 8;
/////////////////////////////////////////////////////////////////////////////
// CBCGPToolbarCustomize
IMPLEMENT_DYNAMIC(CBCGPToolbarCustomize, CPropertySheet)
CBCGPToolbarCustomize::CBCGPToolbarCustomize(
CFrameWnd* pWndParentFrame,
BOOL bAutoSetFromMenus /* = FALSE */,
UINT uiFlags /* = 0xFFFF */,
CList<CRuntimeClass*,CRuntimeClass*>* plistCustomPages /* = NULL */)
: CPropertySheet(_T(""), pWndParentFrame),
m_bAutoSetFromMenus (bAutoSetFromMenus),
m_uiFlags (uiFlags)
{
if((m_uiFlags & BCGCUSTOMIZE_MENUAMPERS) == 0)
{
m_bSaveMenuAmps = FALSE;
}else
{
m_bSaveMenuAmps = TRUE;
}
//-------------------------------
// ET: Add optional custom pages:
//-------------------------------
if (plistCustomPages != NULL)
{
// does not use lib local resources, so moved to front
ASSERT_VALID(plistCustomPages);
for(POSITION pos=plistCustomPages->GetHeadPosition(); pos; )
{
CRuntimeClass* pClass = plistCustomPages->GetNext(pos);
m_listCustomPages.AddTail( (CPropertyPage*) pClass->CreateObject() );
}
}
if (!CBCGPVisualManager::GetInstance ()->IsLook2000Allowed ())
{
m_uiFlags &= ~BCGCUSTOMIZE_LOOK_2000;
}
#if defined _AFXDLL && !defined _BCGCBPRO_STATIC_ // Skins manager can not be used in the static version
if (g_pSkinManager == NULL)
{
ASSERT ((m_uiFlags & BCGCUSTOMIZE_SELECT_SKINS) == 0);
m_uiFlags &= ~BCGCUSTOMIZE_SELECT_SKINS;
}
#else
m_uiFlags &= ~BCGCUSTOMIZE_SELECT_SKINS;
#endif
CBCGPLocalResource locaRes;
ASSERT (pWndParentFrame != NULL);
m_pParentFrame = pWndParentFrame;
m_pCustomizePage = new CBCGPCustomizePage;
m_pToolbarsPage = new CBCGPToolbarsPage (m_pParentFrame);
m_pKeyboardPage = new CBCGPKeyboardPage (m_pParentFrame, m_bAutoSetFromMenus);
m_pMenuPage = new CBCGPMenuPage (m_pParentFrame, m_bAutoSetFromMenus);
m_pMousePage = new CBCGPMousePage;
//---------------------------------------
// Add two main pages (available always):
//---------------------------------------
AddPage (m_pCustomizePage);
AddPage (m_pToolbarsPage);
//----------------
// Add tools page:
//----------------
if (m_uiFlags & BCGCUSTOMIZE_NOTOOLS)
{
m_pToolsPage = NULL;
}
else
{
m_pToolsPage = new CBCGPToolsPage ();
if (g_pUserToolsManager != NULL)
{
AddPage (m_pToolsPage);
}
}
//---------------------------------------------------------
// 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;
CBCGPMDIFrameWnd* pMainMDIFrame = DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, m_pParentFrame);
if (pMainMDIFrame != NULL)
{
bMenuBarIsAvailable = (pMainMDIFrame->IsMenuBarAvailable ());
}
else
{
CBCGPFrameWnd* pMainFrame = DYNAMIC_DOWNCAST (CBCGPFrameWnd, 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 CBCGPOptionsPage (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);
if (m_pKeyboardPage != NULL)
{
m_pKeyboardPage->SetAllCategory (m_strAllCommands);
}
SetTitle (strCaption);
if (m_bAutoSetFromMenus)
{
SetupFromMenus ();
}
//-------------------------
// Add a "New menu" button:
//-------------------------
CString strNewMenu;
strNewMenu.LoadString (IDS_BCGBARRES_NEW_MENU);
AddButton (strNewMenu, CBCGPToolbarMenuButton (0, NULL, -1, strNewMenu));
}
//**************************************************************************************
CBCGPToolbarCustomize::~CBCGPToolbarCustomize()
{
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;
if (m_pToolsPage != NULL)
{
delete m_pToolsPage;
}
//--------------------------------------
// ET: delete all optional custom pages:
//--------------------------------------
while(!m_listCustomPages.IsEmpty())
{
delete m_listCustomPages.RemoveHead();
}
}
BEGIN_MESSAGE_MAP(CBCGPToolbarCustomize, CPropertySheet)
//{{AFX_MSG_MAP(CBCGPToolbarCustomize)
ON_WM_CREATE()
ON_WM_HELPINFO()
ON_WM_CONTEXTMENU()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCGPToolbarCustomize message handlers
int CBCGPToolbarCustomize::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
{
return -1;
}
if (m_uiFlags & BCGCUSTOMIZE_CONTEXT_HELP)
{
ModifyStyleEx (0, WS_EX_CONTEXTHELP);
}
g_pWndCustomize = this;
return 0;
}
//**************************************************************************************
void CBCGPToolbarCustomize::PostNcDestroy()
{
g_pWndCustomize = NULL;
SetFrameCustMode (FALSE);
CPropertySheet::PostNcDestroy();
delete this;
}
//**************************************************************************************
void CBCGPToolbarCustomize::AddButton (UINT uiCategoryId, const CBCGPToolbarButton& button,
int iInsertAfter)
{
CString strCategory;
strCategory.LoadString (uiCategoryId);
AddButton (strCategory, button, iInsertAfter);
}
//**************************************************************************************
void CBCGPToolbarCustomize::AddButton (LPCTSTR lpszCategory, const CBCGPToolbarButton& button,
int iInsertAfter)
{
int iId = (int) button.m_nID;
if (!button.IsEditable ())
{
//------------------------------------------------------
// Don't add protected, MRU, system and Window commands:
//------------------------------------------------------
return;
}
if (!CBCGPToolBar::IsCommandPermitted (button.m_nID))
{
return;
}
CString strText = button.m_strText;
strText.TrimLeft ();
strText.TrimRight ();
BOOL bToolBtn = FALSE;
if (g_pUserToolsManager != NULL &&
g_pUserToolsManager->IsUserToolCmd (iId))
{
CBCGPUserTool* pTool = g_pUserToolsManager->FindTool (iId);
if (pTool == NULL)
{
//------------------------------
// Undefined user tool, skip it
//------------------------------
return;
}
ASSERT_VALID (pTool);
//------------------------
// Use tool name as label:
//------------------------
strText = pTool->m_strLabel;
bToolBtn = TRUE;
}
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
{
if(!m_bSaveMenuAmps)
{
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;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
if ((pButton->m_nID == button.m_nID && pButton->m_nID != (UINT) -1)
|| (pButton->m_nID == (UINT) -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 CBCGPToolbarButton object (MFC class factory is used):
//-------------------------------------------------------------------
CRuntimeClass* pClass = button.GetRuntimeClass ();
ASSERT (pClass != NULL);
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pClass->CreateObject ();
ASSERT_VALID (pButton);
pButton->CopyFrom (button);
pButton->m_strText = strText;
if (bToolBtn)
{
pButton->SetImage (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -