KeyConfigDlg.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * KeyConfigDlg.h
  3. * --------------
  4. * Purpose: Implementation of OpenMPT's keyboard configuration dialog.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "Mainfrm.h"
  12. #include "InputHandler.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. class COptionsKeyboard;
  15. // Might promote to class so we can add rules
  16. // (eg automatically do note off stuff, generate chord keybindings from notes based just on modifier.
  17. // Would need GUI rules too as options would be different for each category
  18. class CommandCategory
  19. {
  20. public:
  21. CommandCategory(const TCHAR *n, InputTargetContext d) : name(n), id(d) { }
  22. bool SeparatorAt(CommandID c) const
  23. {
  24. return mpt::contains(separators, c);
  25. }
  26. void AddCommands(CommandID first, CommandID last, bool addSeparatorAtEnd = false);
  27. CString name;
  28. InputTargetContext id;
  29. std::vector<CommandID> separators;
  30. std::vector<CommandID> commands;
  31. };
  32. class CCustEdit: public CEdit
  33. {
  34. protected:
  35. COptionsKeyboard *m_pOptKeyDlg;
  36. HWND m_hParent = nullptr;
  37. UINT m_nCtrlId = 0;
  38. bool m_isFocussed = false, m_isDummy = false;
  39. public:
  40. FlagSet<Modifiers> mod = ModNone;
  41. UINT code = 0;
  42. CCustEdit(bool dummyField) : m_isDummy(dummyField) { }
  43. void SetParent(HWND h, UINT nID, COptionsKeyboard *pOKD)
  44. {
  45. m_hParent = h;
  46. m_nCtrlId = nID;
  47. m_pOptKeyDlg = pOKD;
  48. }
  49. void SetKey(FlagSet<Modifiers> mod, UINT code);
  50. BOOL PreTranslateMessage(MSG *pMsg) override;
  51. afx_msg void OnSetFocus(CWnd* pOldWnd);
  52. afx_msg void OnKillFocus(CWnd* pNewWnd);
  53. afx_msg LRESULT OnMidiMsg(WPARAM, LPARAM);
  54. DECLARE_MESSAGE_MAP()
  55. };
  56. class COptionsKeyboard: public CPropertyPage
  57. {
  58. protected:
  59. CListBox m_lbnHotKeys;
  60. CListBox m_lbnCommandKeys;
  61. CComboBox m_cmbKeyChoice;
  62. CComboBox m_cmbCategory;
  63. CButton m_bKeyDown, m_bKeyHold, m_bKeyUp;
  64. CButton m_bnReset;
  65. CCustEdit m_eCustHotKey, m_eFindHotKey;
  66. CEdit m_eFind;
  67. CEdit m_eReport, m_eChordWaitTime;
  68. CommandID m_curCommand = kcNull;
  69. int m_curCategory = -1, m_curKeyChoice = -1;
  70. mpt::PathString m_fullPathName;
  71. std::unique_ptr<CCommandSet> m_localCmdSet;
  72. bool m_forceUpdate = false;
  73. void ForceUpdateGUI();
  74. void UpdateShortcutList(int category = -1);
  75. void UpdateCategory();
  76. int GetCategoryFromCommandID(CommandID command) const;
  77. public:
  78. COptionsKeyboard() : CPropertyPage(IDD_OPTIONS_KEYBOARD), m_eCustHotKey(false), m_eFindHotKey(true) { }
  79. std::vector<CommandCategory> commandCategories;
  80. void DefineCommandCategories();
  81. void OnSetKeyChoice();
  82. protected:
  83. BOOL OnInitDialog() override;
  84. void OnOK() override;
  85. BOOL OnSetActive() override;
  86. void DoDataExchange(CDataExchange* pDX) override;
  87. afx_msg void UpdateDialog();
  88. afx_msg void OnKeyboardChanged();
  89. afx_msg void OnKeyChoiceSelect();
  90. afx_msg void OnCommandKeySelChanged();
  91. afx_msg void OnCategorySelChanged();
  92. afx_msg void OnSearchTermChanged();
  93. afx_msg void OnChordWaitTimeChanged();
  94. afx_msg void OnSettingsChanged() { SetModified(TRUE); }
  95. afx_msg void OnCheck() { OnSetKeyChoice(); };
  96. afx_msg void OnNotesRepeat();
  97. afx_msg void OnNoNotesRepeat();
  98. afx_msg void OnDeleteKeyChoice();
  99. afx_msg void OnRestoreKeyChoice();
  100. afx_msg void OnLoad();
  101. afx_msg void OnSave();
  102. afx_msg void OnClearLog();
  103. afx_msg void OnRestoreDefaultKeymap();
  104. afx_msg void OnClearHotKey();
  105. afx_msg void OnFindHotKey();
  106. afx_msg void OnDestroy();
  107. DECLARE_MESSAGE_MAP()
  108. };
  109. OPENMPT_NAMESPACE_END