From 35d128d36f1956eb4c563ff7ba5da2c6703ccda5 Mon Sep 17 00:00:00 2001 From: Johannes Schultz Date: Mon, 14 Oct 2024 18:47:26 +0000 Subject: [PATCH] Merged revision(s) 21811, 21814 from trunk/OpenMPT: [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 --- mptrack/KeyConfigDlg.cpp | 62 ++++++++++++++++++++++++++++++++-------- mptrack/KeyConfigDlg.h | 8 ++++++ mptrack/mptrack.rc | 15 +++++----- 3 files changed, 66 insertions(+), 19 deletions(-) diff --git a/mptrack/KeyConfigDlg.cpp b/mptrack/KeyConfigDlg.cpp index 9429ce44904..d74bcdf8bf7 100644 --- a/mptrack/KeyConfigDlg.cpp +++ b/mptrack/KeyConfigDlg.cpp @@ -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) { @@ -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) @@ -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() @@ -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; } @@ -522,19 +526,25 @@ void COptionsKeyboard::OnCommandKeySelChanged() const CommandID cmd = static_cast(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; } @@ -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); @@ -572,6 +576,8 @@ void COptionsKeyboard::OnCommandKeySelChanged() //Fills or clears key choice info void COptionsKeyboard::OnKeyChoiceSelect() { + EnableKeyChoice(false); + int choice = static_cast(m_cmbKeyChoice.GetItemData(m_cmbKeyChoice.GetCurSel())); CommandID cmd = m_curCommand; @@ -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; @@ -673,6 +709,8 @@ void COptionsKeyboard::OnDeleteKeyChoice() void COptionsKeyboard::OnSetKeyChoice() { + EnableKeyChoice(false); + CommandID cmd = m_curCommand; if(cmd == kcNull) { diff --git a/mptrack/KeyConfigDlg.h b/mptrack/KeyConfigDlg.h index befd1a9ddbf..2add5b0b07c 100644 --- a/mptrack/KeyConfigDlg.h +++ b/mptrack/KeyConfigDlg.h @@ -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 mod = ModNone; @@ -60,6 +61,9 @@ class CCustEdit: public CEdit m_pOptKeyDlg = pOKD; } void SetKey(FlagSet 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; @@ -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(); @@ -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(); @@ -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() diff --git a/mptrack/mptrack.rc b/mptrack/mptrack.rc index de76e856b10..87bcb15cf25 100644 --- a/mptrack/mptrack.rc +++ b/mptrack/mptrack.rc @@ -1246,12 +1246,13 @@ 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 @@ -1259,11 +1260,11 @@ BEGIN 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