📄 cbcgtoolbarcustomizepages.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This source code is a part of BCGControlBar library.
// You may use, compile or redistribute it as part of your application
// for free. You cannot redistribute it as a part of a software development
// library without the agreement of the author. If the sources are
// distributed along with the application, you should leave the original
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
//
// Stas Levin <stas@iet.co.il>
//*******************************************************************************
// CBCGToolbarCustomizePages.cpp : implementation file
//
#include "stdafx.h"
#include <afxpriv.h>
#include "bcgbarres.h"
#include "CBCGToolbarCustomize.h"
#include "CBCGToolbarCustomizePages.h"
#include "BCGtoolbar.h"
#include "BCGToolbarButton.h"
#include "bcglocalres.h"
#include "BCGPopupMenuBar.h"
#include "ToolbarNameDlg.h"
#include "BCGCommandManager.h"
#include "BCGMDIFrameWnd.h"
#include "BCGFrameWnd.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CBCGCustomizePage, CPropertyPage)
IMPLEMENT_DYNCREATE(CBCGToolbarsPage, CPropertyPage)
extern CObList gAllToolbars;
/////////////////////////////////////////////////////////////////////////////
// CBCGCustomizePage property page
CBCGCustomizePage::CBCGCustomizePage() :
CPropertyPage(CBCGCustomizePage::IDD)
{
//{{AFX_DATA_INIT(CBCGCustomizePage)
m_strButtonDescription = _T("");
//}}AFX_DATA_INIT
}
CBCGCustomizePage::~CBCGCustomizePage()
{
}
void CBCGCustomizePage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBCGCustomizePage)
DDX_Control(pDX, IDC_BCGBARRES_CATEGORY, m_wndCategory);
DDX_Control(pDX, IDC_BCGBARRES_USER_TOOLS, m_wndTools);
DDX_Text(pDX, IDC_BCGBARRES_BUTTON_DESCR, m_strButtonDescription);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBCGCustomizePage, CPropertyPage)
//{{AFX_MSG_MAP(CBCGCustomizePage)
ON_LBN_SELCHANGE(IDC_BCGBARRES_USER_TOOLS, OnSelchangeUserTools)
ON_LBN_SELCHANGE(IDC_BCGBARRES_CATEGORY, OnSelchangeCategory)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CBCGCustomizePage::OnSelchangeCategory()
{
UpdateData ();
int iIndex = m_wndCategory.GetCurSel ();
if (iIndex == LB_ERR)
{
ASSERT (FALSE);
return;
}
CWaitCursor wait;
m_wndTools.SetRedraw (FALSE);
m_wndTools.ResetContent ();
//------------------------------------------
// Only "All commands" list shoud be sorted!
//------------------------------------------
CString strCategory;
m_wndCategory.GetText (iIndex, strCategory);
BOOL bAllCommands = (strCategory == m_strAllCategory);
OnChangeSelButton (NULL);
CObList* pCategoryButtonsList =
(CObList*) m_wndCategory.GetItemData (iIndex);
ASSERT_VALID (pCategoryButtonsList);
for (POSITION pos = pCategoryButtonsList->GetHeadPosition (); pos != NULL;)
{
CBCGToolbarButton* pButton = (CBCGToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
pButton->m_bUserButton = (CMD_MGR.GetCmdImage (pButton->m_nID, FALSE) == -1);
int iIndex = -1;
if (bAllCommands)
{
for (int i = 0; iIndex == -1 && i < m_wndTools.GetCount (); i ++)
{
CString strCommand;
m_wndTools.GetText (i, strCommand);
if (strCommand > pButton->m_strText)
{
iIndex = m_wndTools.InsertString (i, pButton->m_strText);
}
}
}
if (iIndex == -1) // Not inserted yet
{
iIndex = m_wndTools.AddString (pButton->m_strText);
}
m_wndTools.SetItemData (iIndex, (DWORD) pButton);
}
m_wndTools.SetRedraw (TRUE);
}
//**************************************************************************************
void CBCGCustomizePage::OnSelchangeUserTools()
{
int iIndex = m_wndTools.GetCurSel ();
if (iIndex == LB_ERR)
{
OnChangeSelButton (NULL);
}
else
{
OnChangeSelButton ((CBCGToolbarButton*) m_wndTools.GetItemData (iIndex));
}
}
//**************************************************************************************
BOOL CBCGCustomizePage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CBCGToolbarCustomize* pWndParent = DYNAMIC_DOWNCAST (CBCGToolbarCustomize, GetParent ());
ASSERT (pWndParent != NULL);
pWndParent->FiilCategotiesListBox (m_wndCategory);
m_wndCategory.SetCurSel (0);
OnSelchangeCategory ();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//**********************************************************************************************
void CBCGCustomizePage::OnChangeSelButton (CBCGToolbarButton* pSelButton)
{
m_strButtonDescription = _T("");
if (pSelButton != NULL)
{
if (pSelButton->m_nID == 0)
{
m_strButtonDescription = pSelButton->m_strText;
}
else
{
CFrameWnd* pParent = GetParentFrame ();
if (pParent != NULL && pParent->GetSafeHwnd () != NULL)
{
pParent->GetMessageString (pSelButton->m_nID,
m_strButtonDescription);
}
}
}
m_pSelButton = pSelButton;
UpdateData (FALSE);
}
//*************************************************************************************
void CBCGCustomizePage::SetUserCategory (LPCTSTR lpszCategory)
{
ASSERT (lpszCategory != NULL);
m_strUserCategory = lpszCategory;
}
//*************************************************************************************
void CBCGCustomizePage::SetAllCategory (LPCTSTR lpszCategory)
{
ASSERT (lpszCategory != NULL);
m_strAllCategory = lpszCategory;
}
/////////////////////////////////////////////////////////////////////////////
// CBCGToolbarsPage property page
CBCGToolbarsPage::CBCGToolbarsPage(CFrameWnd* pParentFrame) :
CPropertyPage(CBCGToolbarsPage::IDD),
m_bUserDefinedToolbars (FALSE),
m_pParentFrame (pParentFrame)
{
//{{AFX_DATA_INIT(CBCGToolbarsPage)
m_bTextLabels = FALSE;
//}}AFX_DATA_INIT
m_pSelectedToolbar = NULL;
ASSERT_VALID (m_pParentFrame);
}
CBCGToolbarsPage::~CBCGToolbarsPage()
{
}
void CBCGToolbarsPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBCGToolbarsPage)
DDX_Control(pDX, IDC_BCGBARRES_TEXT_LABELS, m_wndTextLabels);
DDX_Control(pDX, IDC_BCGBARRES_RENAME_TOOLBAR, m_bntRenameToolbar);
DDX_Control(pDX, IDC_BCGBARRES_NEW_TOOLBAR, m_btnNewToolbar);
DDX_Control(pDX, IDC_BCGBARRES_DELETE_TOOLBAR, m_btnDelete);
DDX_Control(pDX, IDC_BCGBARRES_RESET, m_btnReset);
DDX_Control(pDX, IDC_BCGBARRES_TOOLBAR_LIST, m_wndToobarList);
DDX_Check(pDX, IDC_BCGBARRES_TEXT_LABELS, m_bTextLabels);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBCGToolbarsPage, CPropertyPage)
//{{AFX_MSG_MAP(CBCGToolbarsPage)
ON_LBN_SELCHANGE(IDC_BCGBARRES_TOOLBAR_LIST, OnSelchangeToolbarList)
ON_LBN_DBLCLK(IDC_BCGBARRES_TOOLBAR_LIST, OnDblclkToolbarList)
ON_BN_CLICKED(IDC_BCGBARRES_RESET, OnReset)
ON_BN_CLICKED(IDC_BCGBARRES_RESET_ALL, OnResetAll)
ON_BN_CLICKED(IDC_BCGBARRES_DELETE_TOOLBAR, OnDeleteToolbar)
ON_BN_CLICKED(IDC_BCGBARRES_NEW_TOOLBAR, OnNewToolbar)
ON_BN_CLICKED(IDC_BCGBARRES_RENAME_TOOLBAR, OnRenameToolbar)
ON_BN_CLICKED(IDC_BCGBARRES_TEXT_LABELS, OnBcgbarresTextLabels)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CBCGToolbarsPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
if (!m_bUserDefinedToolbars)
{
m_btnNewToolbar.EnableWindow (FALSE);
m_btnNewToolbar.ShowWindow (SW_HIDE);
m_btnDelete.ShowWindow (SW_HIDE);
m_bntRenameToolbar.ShowWindow (SW_HIDE);
}
for (POSITION pos = gAllToolbars.GetHeadPosition (); pos != NULL;)
{
CBCGToolBar* pToolBar = (CBCGToolBar*) gAllToolbars.GetNext (pos);
ASSERT (pToolBar != NULL);
if (CWnd::FromHandlePermanent (pToolBar->m_hWnd) != NULL)
{
ASSERT_VALID(pToolBar);
//----------------------------------------------------------------------
// Check, if toolbar belongs to this dialog's parent main frame window
// (by Peter Schregle):
//----------------------------------------------------------------------
if (m_pParentFrame->GetTopLevelFrame() == pToolBar->GetTopLevelFrame () &&
!pToolBar->IsKindOf (RUNTIME_CLASS (CBCGPopupMenuBar)) &&
!pToolBar->m_bMasked)
{
CString strName;
pToolBar->GetWindowText (strName);
if (strName.IsEmpty ())
{
CBCGLocalResource locaRes;
strName.LoadString (IDS_BCGBARRES_UNTITLED_TOOLBAR);
}
int iIndex = m_wndToobarList.AddString (strName);
m_wndToobarList.SetItemData (iIndex, (DWORD) pToolBar);
if (pToolBar->GetStyle () & WS_VISIBLE)
{
m_wndToobarList.SetCheck (iIndex, 1);
}
m_wndToobarList.EnableCheck (iIndex, pToolBar->CanBeClosed ());
}
}
}
CBCGToolbarCustomize* pWndParent = DYNAMIC_DOWNCAST (CBCGToolbarCustomize, GetParent ());
ASSERT (pWndParent != NULL);
if ((pWndParent->GetFlags () & BCGCUSTOMIZE_TEXT_LABELS) == 0)
{
m_wndTextLabels.ShowWindow (SW_HIDE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//*************************************************************************************
void CBCGToolbarsPage::OnSelchangeToolbarList()
{
int iIndex = m_wndToobarList.GetCurSel ();
if (iIndex == LB_ERR)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -