KeyDropDownControl.h
1 #pragma once 2 3 #include <keyboardmanager/common/Shortcut.h> 4 5 // Enables the WinUI teaching tip to show as the new warning flyout 6 #define USE_NEW_DROPDOWN_WARNING_TIP 7 8 namespace KBMEditor 9 { 10 class KeyboardManagerState; 11 } 12 13 class MappingConfiguration; 14 15 namespace winrt::Windows 16 { 17 namespace Foundation 18 { 19 struct hstring; 20 } 21 22 namespace UI::Xaml::Controls 23 { 24 struct RelativePanel; 25 struct StackPanel; 26 struct ComboBox; 27 struct Flyout; 28 struct TextBlock; 29 } 30 } 31 32 enum class ShortcutErrorType; 33 34 // Wrapper class for the key drop down menu 35 class KeyDropDownControl 36 { 37 private: 38 // Stores the drop down combo box 39 winrt::Windows::Foundation::IInspectable dropDown; 40 41 // Stores the previous layout 42 HKL previousLayout = 0; 43 44 #ifdef USE_NEW_DROPDOWN_WARNING_TIP 45 // Stores the teaching tip attached to the current drop down 46 muxc::TeachingTip warningTip; 47 #else 48 // Stores the flyout warning message 49 winrt::Windows::Foundation::IInspectable warningMessage; 50 51 // Stores the flyout attached to the current drop down 52 winrt::Windows::Foundation::IInspectable warningFlyout; 53 #endif 54 55 // Stores whether a key to shortcut warning has to be ignored 56 bool ignoreKeyToShortcutWarning; 57 58 // Function to set properties apart from the SelectionChanged event handler 59 void SetDefaultProperties(bool isShortcut, bool renderDisable); 60 61 // Function to check if the layout has changed and accordingly update the drop down list 62 void CheckAndUpdateKeyboardLayout(ComboBox currentDropDown, bool isShortcut, bool renderDisable); 63 64 // Get selected value of dropdown or -1 if nothing is selected 65 static DWORD GetSelectedValue(ComboBox comboBox); 66 static DWORD GetSelectedValue(TextBlock text); 67 68 // Function to set accessible name for combobox 69 static void SetAccessibleNameForComboBox(ComboBox dropDown, int index); 70 71 public: 72 // Pointer to the keyboard manager state 73 static KBMEditor::KeyboardManagerState* keyboardManagerState; 74 static MappingConfiguration* mappingConfiguration; 75 76 // Constructor - the last default parameter should be passed as false only if it originates from Type shortcut or when an old shortcut is reloaded 77 KeyDropDownControl(bool isShortcut, bool fromAddShortcutToControl = false, bool renderDisable = false) : 78 ignoreKeyToShortcutWarning(fromAddShortcutToControl) 79 { 80 SetDefaultProperties(isShortcut, renderDisable); 81 } 82 83 // Function to set selection handler for single key remap drop down. Needs to be called after the constructor since the singleKeyControl StackPanel is null if called in the constructor 84 void SetSelectionHandler(StackPanel& table, StackPanel row, int colIndex, RemapBuffer& singleKeyRemapBuffer); 85 86 // Function for validating the selection of shortcuts for the drop down 87 std::pair<ShortcutErrorType, int> ValidateShortcutSelection(StackPanel table, StackPanel row, VariableSizedWrapGrid parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); 88 89 // Function to set selection handler for shortcut drop down. 90 void SetSelectionHandler(StackPanel& table, StackPanel row, winrt::Windows::UI::Xaml::Controls::VariableSizedWrapGrid parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp, bool isHybridControl, bool isSingleKeyWindow); 91 92 // Function to return the combo box element of the drop down 93 ComboBox GetComboBox(); 94 95 // Function to add a drop down to the shortcut stack panel 96 static void AddDropDown(StackPanel& table, StackPanel row, winrt::Windows::UI::Xaml::Controls::VariableSizedWrapGrid parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning = false); 97 98 // Function to get the list of key codes from the shortcut combo box stack panel 99 static std::vector<int32_t> GetSelectedCodesFromStackPanel(VariableSizedWrapGrid parent); 100 101 // Function for validating the selection of shortcuts for all the associated drop downs 102 static void ValidateShortcutFromDropDownList(StackPanel table, StackPanel row, VariableSizedWrapGrid parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); 103 104 // Function to set the warning message 105 void SetDropDownError(winrt::Windows::UI::Xaml::Controls::ComboBox currentDropDown, winrt::hstring message); 106 107 // Set selected Value 108 void SetSelectedValue(std::wstring value); 109 110 // Function to add a shortcut to the UI control as combo boxes 111 static void AddShortcutToControl(Shortcut shortcut, StackPanel table, VariableSizedWrapGrid parent, KBMEditor::KeyboardManagerState& keyboardManagerState, const int colIndex, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, RemapBuffer& remapBuffer, StackPanel row, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); 112 113 // Get keys name list depending if Disable is in dropdown 114 static std::vector<std::pair<DWORD, std::wstring>> GetKeyList(bool isShortcut, bool renderDisable); 115 116 // Get number of selected keys. Do not count -1 and 0 values as they stand for Not selected and None 117 static int GetNumberOfSelectedKeys(std::vector<int32_t> keys); 118 119 bool exactMatch = false; 120 };