📄 bcgpkeymapdlg.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.
//*******************************************************************************
// BCGPKeyMapDlg.cpp : implementation file
//
#include "stdafx.h"
#ifndef BCG_NO_CUSTOMIZATION
#include "BCGCBPro.h"
#include "BCGPKeyMapDlg.h"
#include "BCGPToolbarCustomize.h"
#include "BCGPMultiDocTemplate.h"
#include "BCGPLocalResource.h"
#include "BCGPToolbarButton.h"
#include "BCGPWorkspace.h"
#include "BCGPRegistry.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static const int iColumnCommand = 0;
static const int iColumnKeys = 1;
static const int iColumnDescr = 2;
static const CString strWindowPlacementRegSection = _T("KeyMapWindowPlacement");
static const CString strRectKey = _T("KeyMapWindowRect");
static int CALLBACK listCompareFunc (
LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// lParamSort contains a pointer to the dialog.
// The lParam of an item is just its index.
CBCGPKeyMapDlg* pDlg = (CBCGPKeyMapDlg*) lParamSort;
ASSERT_VALID (pDlg);
LVFINDINFO info;
info.flags = LVFI_PARAM;
info.lParam = lParam1;
int iIndex1 = pDlg->m_KeymapList.FindItem (&info);
ASSERT (iIndex1 >= 0);
info.lParam = lParam2;
int iIndex2 = pDlg->m_KeymapList.FindItem (&info);
ASSERT (iIndex2 >= 0);
CString strItem1 = pDlg->m_KeymapList.GetItemText (iIndex1, pDlg->m_nSortedCol);
CString strItem2 = pDlg->m_KeymapList.GetItemText (iIndex2, pDlg->m_nSortedCol);
return pDlg->m_bSortAscending ?
strItem1.Compare (strItem2) :
strItem2.Compare (strItem1);
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPKeyMapDlg dialog
CBCGPKeyMapDlg::CBCGPKeyMapDlg(CFrameWnd* pWndParentFrame,
BOOL bEnablePrint /* = FALSE */)
: CDialog(CBCGPKeyMapDlg::IDD, pWndParentFrame),
m_bEnablePrint (bEnablePrint)
{
m_pWndParentFrame = pWndParentFrame;
//{{AFX_DATA_INIT(CBCGPKeyMapDlg)
//}}AFX_DATA_INIT
m_hAccelTable = NULL;
m_lpAccel = NULL;
m_nAccelSize = 0;
m_nSortedCol = 0;
m_bSortAscending = TRUE;
m_hInstDefault = NULL;
}
CBCGPKeyMapDlg::~CBCGPKeyMapDlg()
{
if (m_pDlgCust != NULL)
{
delete m_pDlgCust;
}
if (m_lpAccel != NULL)
{
delete m_lpAccel;
}
}
void CBCGPKeyMapDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBCGPKeyMapDlg)
DDX_Control(pDX, IDC_BCGBARRES_ACCEL_LABEL, m_wndAccelLabel);
DDX_Control(pDX, IDC_BCGBARRES_KEYLIST, m_KeymapList);
DDX_Control(pDX, IDC_BCGBARRES_CATEGORY, m_wndCategoryList);
DDX_Control(pDX, IDC_BCGBARRES_VIEW_ICON, m_wndViewIcon);
DDX_Control(pDX, IDC_BCGBARRES_VIEW_TYPE, m_wndViewTypeList);
DDX_Control(pDX, IDC_BCGBARRES_PRINT_KEYMAP, m_ButtonPrint);
DDX_Control(pDX, IDC_BCGBARRES_COPY_KEYMAP, m_ButtonCopy);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBCGPKeyMapDlg, CDialog)
//{{AFX_MSG_MAP(CBCGPKeyMapDlg)
ON_CBN_SELCHANGE(IDC_BCGBARRES_VIEW_TYPE, OnSelchangeViewType)
ON_CBN_SELCHANGE(IDC_BCGBARRES_CATEGORY, OnSelchangeCategory)
ON_BN_CLICKED(IDC_BCGBARRES_COPY_KEYMAP, OnCopy)
ON_BN_CLICKED(IDC_BCGBARRES_PRINT_KEYMAP, OnPrint)
ON_WM_SIZE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCGPKeyMapDlg message handlers
BOOL CBCGPKeyMapDlg::OnInitDialog()
{
CDialog::OnInitDialog();
{
CBCGPLocalResource locaRes;
//-----------------
// Set dialog icon:
//-----------------
SetIcon ((HICON) ::LoadImage (
AfxGetResourceHandle (),
MAKEINTRESOURCE (IDI_BCGBARRES_HELP),
IMAGE_ICON,
::GetSystemMetrics (SM_CXSMICON),
::GetSystemMetrics (SM_CYSMICON),
LR_SHARED), FALSE);
//---------------
// Setup buttons:
//---------------
m_ButtonPrint.m_nFlatStyle = CBCGPButton::BUTTONSTYLE_FLAT;
m_ButtonCopy.m_nFlatStyle = CBCGPButton::BUTTONSTYLE_FLAT;
CString strTT;
if (m_bEnablePrint)
{
m_ButtonPrint.SetImage (IDB_BCGBARRES_PRINT, NULL);
m_ButtonPrint.GetWindowText (strTT);
m_ButtonPrint.SetWindowText (_T(""));
m_ButtonPrint.SetTooltip (strTT);
m_ButtonPrint.SizeToContent ();
m_ButtonPrint.m_bDrawFocus = FALSE;
}
else
{
m_ButtonPrint.ShowWindow (SW_HIDE);
}
m_ButtonCopy.SetImage (IDB_BCGBARRES_COPY, NULL);
m_ButtonCopy.GetWindowText (strTT);
m_ButtonCopy.SetWindowText (_T(""));
m_ButtonCopy.SetTooltip (strTT);
m_ButtonCopy.SizeToContent ();
m_ButtonCopy.m_bDrawFocus = FALSE;
//-------------
// Add columns:
//-------------
OnSetColumns ();
SetColumnsWidth ();
}
//-------------------------------------------------------------
// Find all application document templates and fill accelerator
// tables combobox by document template data:
//-------------------------------------------------------------
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (pDocManager != NULL)
{
//---------------------------------------
// Walk all templates in the application:
//---------------------------------------
for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
{
CBCGPMultiDocTemplate* pTemplate =
(CBCGPMultiDocTemplate*) pDocManager->GetNextDocTemplate (pos);
ASSERT_VALID (pTemplate);
ASSERT_KINDOF (CDocTemplate, pTemplate);
//-----------------------------------------------------
// We are interessing CBCGPMultiDocTemplate objects with
// the shared menu only....
//-----------------------------------------------------
if (!pTemplate->IsKindOf (RUNTIME_CLASS (CMultiDocTemplate)) ||
pTemplate->m_hAccelTable == NULL)
{
continue;
}
CString strName;
pTemplate->GetDocString (strName, CDocTemplate::fileNewName);
int iIndex = m_wndViewTypeList.AddString (strName);
m_wndViewTypeList.SetItemData (iIndex, (DWORD) pTemplate);
}
}
//--------------------------
// Add a default application:
//--------------------------
CFrameWnd* pWndMain = DYNAMIC_DOWNCAST (CFrameWnd, m_pWndParentFrame);
if (pWndMain != NULL && pWndMain->m_hAccelTable != NULL)
{
CBCGPLocalResource locaRes;
CString strName;
strName.LoadString (IDS_BCGBARRES_DEFAULT_VIEW);
int iIndex = m_wndViewTypeList.AddString (strName);
m_wndViewTypeList.SetItemData (iIndex, (DWORD) NULL);
m_wndViewTypeList.SetCurSel (iIndex);
OnSelchangeViewType();
}
m_KeymapList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
OnSelchangeViewType ();
//---------------------------------
// Initialize commands by category:
//---------------------------------
m_pDlgCust = new CBCGPToolbarCustomize(m_pWndParentFrame, TRUE);
m_pDlgCust->EnableUserDefinedToolbars();
m_pDlgCust->FillCategoriesComboBox (m_wndCategoryList);
m_wndCategoryList.SetCurSel (0);
OnSelchangeCategory ();
//----------------------------------
// Restore window position and size:
//----------------------------------
if (GetWorkspace () != NULL)
{
CBCGPRegistrySP regSP;
CBCGPRegistry& reg = regSP.Create (FALSE, TRUE);
CRect rectPosition;
if (reg.Open (GetWorkspace ()->GetRegSectionPath (strWindowPlacementRegSection)) &&
reg.Read (strRectKey, rectPosition))
{
MoveWindow (rectPosition);
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//*************************************************************************************
void CBCGPKeyMapDlg::OnSelchangeViewType()
{
m_hAccelTable = NULL;
if (m_lpAccel != NULL)
{
delete m_lpAccel;
m_lpAccel = NULL;
}
int iIndex = m_wndViewTypeList.GetCurSel ();
if (iIndex == CB_ERR)
{
m_wndViewIcon.SetIcon (NULL);
return;
}
HICON hicon = NULL;
CBCGPMultiDocTemplate* pTemplate =
(CBCGPMultiDocTemplate*) m_wndViewTypeList.GetItemData (iIndex);
if (pTemplate != NULL)
{
ASSERT_VALID (pTemplate);
hicon = ::LoadIcon (m_hInstDefault, MAKEINTRESOURCE (pTemplate->GetResId ()));
m_hAccelTable = pTemplate->m_hAccelTable;
}
else
{
CFrameWnd* pWndMain = DYNAMIC_DOWNCAST (CFrameWnd, m_pWndParentFrame);
if (pWndMain != NULL)
{
hicon = (HICON) GetClassLong (*pWndMain, GCL_HICON);
m_hAccelTable = pWndMain->m_hAccelTable;
}
}
if (hicon == NULL)
{
hicon = ::LoadIcon(NULL, IDI_APPLICATION);
}
m_wndViewIcon.SetIcon (hicon);
ASSERT (m_hAccelTable != NULL);
m_nAccelSize = ::CopyAcceleratorTable (m_hAccelTable, NULL, 0);
m_lpAccel = new ACCEL [m_nAccelSize];
ASSERT (m_lpAccel != NULL);
::CopyAcceleratorTable (m_hAccelTable, m_lpAccel, m_nAccelSize);
OnSelchangeCategory ();
}
//*************************************************************************************
void CBCGPKeyMapDlg::OnSelchangeCategory()
{
UpdateData ();
ASSERT (m_lpAccel != NULL);
int iIndex = m_wndCategoryList.GetCurSel ();
if (iIndex == LB_ERR)
{
return;
}
CObList* pCategoryButtonsList = (CObList*) m_wndCategoryList.GetItemData (iIndex);
ASSERT_VALID (pCategoryButtonsList);
HINSTANCE hInstRes = AfxGetResourceHandle ();
AfxSetResourceHandle (m_hInstDefault);
int nItem = 0;
m_KeymapList.DeleteAllItems();
for (POSITION pos = pCategoryButtonsList->GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) pCategoryButtonsList->GetNext (pos);
ASSERT (pButton != NULL);
if (pButton->m_nID > 0 && pButton->m_nID != (UINT) -1)
{
OnInsertItem (pButton, nItem ++);
}
}
m_KeymapList.SortItems (listCompareFunc, (LPARAM) this);
AfxSetResourceHandle (hInstRes);
}
//*************************************************************************************
void CBCGPKeyMapDlg::OnCopy()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -