|
// Copyright (C) 2011 Fog Creek Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
#include "KeyboardHelpDialog.h"
#include "RegistryConfig.h"
#include "GlobalData.h"
static CString GetKeyName(UINT uKey, bool bExtended = false)
{
UINT uScanCode = ::MapVirtualKey(uKey, MAPVK_VK_TO_VSC);
LONG lParam = (LONG)uScanCode << 16;
// Adding this flag prevents a distinction from being made between the left and
// right Alt, Control, or Shift keys.
lParam |= (1 << 25);
// Adding this flag is necessary for certain keys (e.g. Insert, Delete) to be
// handled properly. However, it prevents other keys (e.g. Shift) from being
// handled properly. Therefore, only use it when necessary.
if (bExtended) lParam |= (1 << 24);
// Get the name of the key.
TCHAR szKeyName[20];
::GetKeyNameText(lParam, szKeyName, 20);
return szKeyName;
}
static CStringW LookupMenuText(CString strName, CString strLang)
{
// Search the context menu list to find the menu text for the specified command.
// Then, attempt to find a localized string in the registry.
for (int i = 0; i < MenuDescListCount; i++)
{
if (MenuDescList[i].strName == strName)
{
CStringW strMenuText = MenuDescList[i].strMenuText;
if (!strLang.IsEmpty())
{
CStringW strDummy;
GetCMenuTranslation(strLang, MenuDescList[i].strName, strMenuText,
strDummy);
}
if (strMenuText.Right(3) == "...")
{
// Strip off any trailing ellipsis from the name.
strMenuText.Truncate(strMenuText.GetLength() - 3);
}
return strMenuText;
}
}
return "";
}
LRESULT CKeyboardHelpDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&)
{
CenterWindow();
// Attempt to load localized dialog strings if they exist.
CString strLang;
GetRegistryConfig("CMenuLang", strLang);
if (!strLang.IsEmpty())
{
CStringW strMenuText;
CStringW strHelpText;
GetCMenuTranslation(strLang, "keyboarddialog", strMenuText, strHelpText);
if (!strMenuText.IsEmpty()) ::SetWindowTextW(m_hWnd, strMenuText);
if (!strHelpText.IsEmpty()) ::SetDlgItemTextW(m_hWnd, IDC_TOPTEXT, strHelpText);
}
// Set tab stops for the list box.
int nTabStop = 100;
SendDlgItemMessage(IDC_KEYLIST, LB_SETTABSTOPS, 1, (LPARAM)&nTabStop);
// Get the names of the Alt, Control, and Shift keys.
CString strAlt = GetKeyName(VK_MENU);
CString strControl = GetKeyName(VK_CONTROL);
CString strShift = GetKeyName(VK_SHIFT);
strAlt += '+';
strControl += '+';
strShift += '+';
// Add each keyboard shortcut to the list box.
for (int i = 0; i < KeyShortcutListCount; i++)
{
CString strKey;
WORD wFlags = KeyShortcutList[i].wFlags;
if (wFlags & KSF_CONTROL) strKey += strControl;
if (wFlags & KSF_ALT) strKey += strAlt;
if (wFlags & KSF_SHIFT) strKey += strShift;
strKey += GetKeyName(KeyShortcutList[i].wKey, true);
strKey += '\t';
strKey += LookupMenuText(KeyShortcutList[i].strName, strLang);
SendDlgItemMessage(IDC_KEYLIST, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)strKey);
}
return 1L;
}
LRESULT CKeyboardHelpDialog::OnOK(WORD, WORD, HWND, BOOL&)
{
EndDialog(IDOK);
return 1L;
}
|
Loading...