Skip to content

Commit

Permalink
Merged revision(s) 21811, 21814 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[Imp] Keyboard config dialog: New shortcuts are now accepted by pressing the new "Set" button or by double-clicking into the shortcut field to improve accesibility (https://bugs.openmpt.org/view.php?id=1825).
........
[Fix] Key config dialog: Avoid focus staying on the disabled hotkey input.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@21816 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Oct 14, 2024
1 parent 6e2a6b5 commit 35d128d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 19 deletions.
62 changes: 50 additions & 12 deletions mptrack/KeyConfigDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LRESULT CCustEdit::OnMidiMsg(WPARAM dwMidiDataParam, LPARAM)

BOOL CCustEdit::PreTranslateMessage(MSG *pMsg)
{
if(pMsg)
if(pMsg && !m_bypassed)
{
if(pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
{
Expand Down Expand Up @@ -122,6 +122,7 @@ BEGIN_MESSAGE_MAP(COptionsKeyboard, CPropertyPage)
ON_LBN_SELCHANGE(IDC_COMMAND_LIST, &COptionsKeyboard::OnCommandKeySelChanged)
ON_LBN_SELCHANGE(IDC_KEYCATEGORY, &COptionsKeyboard::OnCategorySelChanged)
ON_EN_UPDATE(IDC_CHORDDETECTWAITTIME, &COptionsKeyboard::OnChordWaitTimeChanged)
ON_COMMAND(IDC_BUTTON1, &COptionsKeyboard::OnListenForKeys)
ON_COMMAND(IDC_DELETE, &COptionsKeyboard::OnDeleteKeyChoice)
ON_COMMAND(IDC_RESTORE, &COptionsKeyboard::OnRestoreKeyChoice)
ON_COMMAND(IDC_LOAD, &COptionsKeyboard::OnLoad)
Expand All @@ -136,6 +137,7 @@ BEGIN_MESSAGE_MAP(COptionsKeyboard, CPropertyPage)
ON_EN_CHANGE(IDC_FIND, &COptionsKeyboard::OnSearchTermChanged)
ON_EN_CHANGE(IDC_FINDHOTKEY, &COptionsKeyboard::OnFindHotKey)
ON_EN_SETFOCUS(IDC_FINDHOTKEY, &COptionsKeyboard::OnClearHotKey)
ON_WM_LBUTTONDBLCLK()
ON_WM_DESTROY()
END_MESSAGE_MAP()

Expand Down Expand Up @@ -187,6 +189,8 @@ BOOL COptionsKeyboard::OnInitDialog()
m_eReport.FmtLines(TRUE);
m_eReport.SetWindowText(_T(""));

EnableKeyChoice(false);

m_eChordWaitTime.SetWindowText(mpt::cfmt::val(TrackerSettings::Instance().gnAutoChordWaitTime.Get()));
return TRUE;
}
Expand Down Expand Up @@ -522,19 +526,25 @@ void COptionsKeyboard::OnCommandKeySelChanged()
const CommandID cmd = static_cast<CommandID>(m_lbnCommandKeys.GetItemData(m_lbnCommandKeys.GetCurSel()));
CString str;

EnableKeyChoice(false);

BOOL enableButton = (cmd == kcNull) ? FALSE : TRUE;
GetDlgItem(IDC_BUTTON1)->EnableWindow(enableButton);
GetDlgItem(IDC_DELETE)->EnableWindow(enableButton);
GetDlgItem(IDC_RESTORE)->EnableWindow(enableButton);
m_cmbKeyChoice.EnableWindow(enableButton);
m_bKeyDown.EnableWindow(enableButton);
m_bKeyHold.EnableWindow(enableButton);
m_bKeyUp.EnableWindow(enableButton);

//Separator
if(cmd == kcNull)
{
m_cmbKeyChoice.SetWindowText(_T(""));
m_cmbKeyChoice.EnableWindow(FALSE);
m_eCustHotKey.SetWindowText(_T(""));
m_eCustHotKey.EnableWindow(FALSE);
m_bKeyDown.SetCheck(0);
m_bKeyDown.EnableWindow(FALSE);
m_bKeyHold.SetCheck(0);
m_bKeyHold.EnableWindow(FALSE);
m_bKeyUp.SetCheck(0);
m_bKeyUp.EnableWindow(FALSE);
m_curCommand = kcNull;
}

Expand All @@ -543,12 +553,6 @@ void COptionsKeyboard::OnCommandKeySelChanged()
{
m_forceUpdate = false;

m_cmbKeyChoice.EnableWindow(TRUE);
m_eCustHotKey.EnableWindow(TRUE);
m_bKeyDown.EnableWindow(TRUE);
m_bKeyHold.EnableWindow(TRUE);
m_bKeyUp.EnableWindow(TRUE);

m_curCommand = cmd;
m_curCategory = GetCategoryFromCommandID(cmd);

Expand All @@ -572,6 +576,8 @@ void COptionsKeyboard::OnCommandKeySelChanged()
//Fills or clears key choice info
void COptionsKeyboard::OnKeyChoiceSelect()
{
EnableKeyChoice(false);

int choice = static_cast<int>(m_cmbKeyChoice.GetItemData(m_cmbKeyChoice.GetCurSel()));
CommandID cmd = m_curCommand;

Expand Down Expand Up @@ -652,6 +658,36 @@ void COptionsKeyboard::OnRestoreKeyChoice()
return;
}


void COptionsKeyboard::OnLButtonDblClk(UINT flags, CPoint point)
{
ClientToScreen(&point);
CRect rect;
m_eCustHotKey.GetWindowRect(rect);
if(m_eCustHotKey.IsBypassed() && rect.PtInRect(point))
EnableKeyChoice(true);
else
CPropertyPage::OnLButtonDblClk(flags, point);
}


void COptionsKeyboard::OnListenForKeys()
{
EnableKeyChoice(m_eCustHotKey.IsBypassed());
}


void COptionsKeyboard::EnableKeyChoice(bool enable)
{
if(!enable && GetFocus() == &m_eCustHotKey)
GetDlgItem(IDC_BUTTON1)->SetFocus();
m_eCustHotKey.Bypass(!enable);
GetDlgItem(IDC_BUTTON1)->SetWindowText(enable ? _T("Cancel") : _T("&Set"));
if(enable)
m_eCustHotKey.SetFocus();
}


void COptionsKeyboard::OnDeleteKeyChoice()
{
CommandID cmd = m_curCommand;
Expand All @@ -673,6 +709,8 @@ void COptionsKeyboard::OnDeleteKeyChoice()

void COptionsKeyboard::OnSetKeyChoice()
{
EnableKeyChoice(false);

CommandID cmd = m_curCommand;
if(cmd == kcNull)
{
Expand Down
8 changes: 8 additions & 0 deletions mptrack/KeyConfigDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CCustEdit: public CEdit
HWND m_hParent = nullptr;
UINT m_nCtrlId = 0;
bool m_isFocussed = false, m_isDummy = false;
bool m_bypassed = false;

public:
FlagSet<Modifiers> mod = ModNone;
Expand All @@ -60,6 +61,9 @@ class CCustEdit: public CEdit
m_pOptKeyDlg = pOKD;
}
void SetKey(FlagSet<Modifiers> mod, UINT code);

void Bypass(bool bypass) { m_bypassed = bypass; EnableWindow(bypass ? FALSE : TRUE); }
bool IsBypassed() const { return m_bypassed; }

protected:
BOOL PreTranslateMessage(MSG *pMsg) override;
Expand Down Expand Up @@ -114,6 +118,8 @@ class COptionsKeyboard: public CPropertyPage
void UnlockControls() { m_lockCount--; MPT_ASSERT(m_lockCount >= 0); }
bool IsLocked() const noexcept { return m_lockCount != 0; }

void EnableKeyChoice(bool enable);

afx_msg void UpdateDialog();
afx_msg void OnKeyboardChanged();
afx_msg void OnKeyChoiceSelect();
Expand All @@ -125,6 +131,7 @@ class COptionsKeyboard: public CPropertyPage
afx_msg void OnCheck() { OnSetKeyChoice(); };
afx_msg void OnNotesRepeat();
afx_msg void OnNoNotesRepeat();
afx_msg void OnListenForKeys();
afx_msg void OnDeleteKeyChoice();
afx_msg void OnRestoreKeyChoice();
afx_msg void OnLoad();
Expand All @@ -133,6 +140,7 @@ class COptionsKeyboard: public CPropertyPage
afx_msg void OnRestoreDefaultKeymap();
afx_msg void OnClearHotKey();
afx_msg void OnFindHotKey();
afx_msg void OnLButtonDblClk(UINT flags, CPoint point);
afx_msg void OnDestroy();

DECLARE_MESSAGE_MAP()
Expand Down
15 changes: 8 additions & 7 deletions mptrack/mptrack.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1246,24 +1246,25 @@ BEGIN
GROUPBOX "Key setup for selected command ",IDC_STATIC,150,6,132,84
COMBOBOX IDC_CHOICECOMBO,156,18,78,51,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Key:",IDC_STATIC,156,38,16,8
EDITTEXT IDC_CUSTHOTKEY,174,36,60,13,ES_AUTOHSCROLL
EDITTEXT IDC_CUSTHOTKEY,174,36,60,13,ES_AUTOHSCROLL | ES_READONLY
PUSHBUTTON "&Set",IDC_BUTTON1,240,36,37,13
PUSHBUTTON "&Restore",IDC_RESTORE,240,54,37,13
PUSHBUTTON "&Delete",IDC_DELETE,240,18,37,13
CONTROL "On Key Down",IDC_CHECKKEYDOWN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,156,54,66,8
CONTROL "On Key Hold",IDC_CHECKKEYHOLD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,156,66,66,8
CONTROL "On Key Up",IDC_CHECKKEYUP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,156,78,66,8
PUSHBUTTON "Restore",IDC_RESTORE,240,36,37,13
PUSHBUTTON "Delete",IDC_DELETE,240,18,37,13
GROUPBOX "Misc",IDC_STATIC,150,96,132,40
LTEXT "Repeat notes on hold?",IDC_STATIC,156,108,74,8
PUSHBUTTON "Yes",IDC_NOTESREPEAT,240,108,18,9
PUSHBUTTON "No",IDC_NONOTESREPEAT,258,108,18,9
LTEXT "Chord detect interval (ms):",IDC_STATIC,156,122,88,8
EDITTEXT IDC_CHORDDETECTWAITTIME,246,120,30,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_RIGHT
GROUPBOX "Keyboard Mapping",IDC_STATIC,150,144,132,48
PUSHBUTTON "Import Keys...",IDC_LOAD,156,156,54,13
PUSHBUTTON "Export Keys...",IDC_SAVE,222,156,54,13
PUSHBUTTON "Restore default configuration",IDC_RESTORE_KEYMAP,156,174,120,12
PUSHBUTTON "&Import Keys...",IDC_LOAD,156,156,54,13
PUSHBUTTON "&Export Keys...",IDC_SAVE,222,156,54,13
PUSHBUTTON "Restore default &configuration",IDC_RESTORE_KEYMAP,156,174,120,12
LTEXT "Error Log:",IDC_STATIC,150,198,78,8
PUSHBUTTON "Clear Log",IDC_CLEARLOG,239,196,42,12
PUSHBUTTON "Clear &Log",IDC_CLEARLOG,239,196,42,12
EDITTEXT IDC_KEYREPORT,150,210,132,66,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
EDITTEXT IDC_FIND,30,264,54,12,ES_AUTOHSCROLL
LTEXT "Find:",IDC_STATIC,6,266,24,8
Expand Down

0 comments on commit 35d128d

Please sign in to comment.