ShortcutControl.h
1 #pragma once 2 3 #include <keyboardmanager/common/Shortcut.h> 4 5 namespace KBMEditor 6 { 7 class KeyboardManagerState; 8 } 9 10 class KeyDropDownControl; 11 namespace winrt::Windows::UI::Xaml 12 { 13 struct XamlRoot; 14 namespace Controls 15 { 16 struct StackPanel; 17 struct TextBox; 18 struct Button; 19 } 20 } 21 22 class ShortcutControl 23 { 24 private: 25 // Wrap grid for the drop downs to display the selected shortcut 26 winrt::Windows::Foundation::IInspectable shortcutDropDownVariableSizedWrapGrid; 27 28 // Button to type the shortcut 29 Button btnPickShortcut; 30 31 // StackPanel to hold the shortcut 32 StackPanel spBtnPickShortcut; 33 34 // StackPanel to parent the above controls 35 winrt::Windows::Foundation::IInspectable shortcutControlLayout; 36 37 // StackPanel to parent the first line of "To" Column 38 winrt::Windows::Foundation::IInspectable keyComboStackPanel; 39 40 // Function to set the accessible name of the target app text box 41 static void SetAccessibleNameForTextBox(TextBox targetAppTextBox, int rowIndex); 42 43 // Function to set the accessible names for all the controls in a row 44 static void UpdateAccessibleNames(StackPanel sourceColumn, StackPanel mappedToColumn, TextBox targetAppTextBox, Button deleteButton, int rowIndex); 45 46 // enum for the type of shortcut, to make it easier to switch on and read 47 enum class ShortcutType 48 { 49 Shortcut, 50 Text, 51 RunProgram, 52 OpenURI 53 }; 54 55 public: 56 // Handle to the current Edit Shortcuts Window 57 static HWND editShortcutsWindowHandle; 58 59 // Pointer to the keyboard manager state 60 static KBMEditor::KeyboardManagerState* keyboardManagerState; 61 62 // Stores the current list of remappings 63 static RemapBuffer shortcutRemapBuffer; 64 65 // Vector to store dynamically allocated KeyDropDownControl objects to avoid early destruction 66 std::vector<std::unique_ptr<KeyDropDownControl>> keyDropDownControlObjects; 67 68 // constructor 69 ShortcutControl(StackPanel table, StackPanel row, const int colIndex, TextBox targetApp); 70 71 // Function to that will CreateDetectShortcutWindow, created here to it can be done automatically when "new shortcut" is clicked. 72 void OpenNewShortcutControlRow(StackPanel table, StackPanel row); 73 74 // Function to add a new row to the shortcut table. If the originalKeys and newKeys args are provided, then the displayed shortcuts are set to those values. 75 static ShortcutControl& AddNewShortcutControlRow(StackPanel& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, const Shortcut& originalKeys = Shortcut(), const KeyShortcutTextUnion& newKeys = Shortcut(), const std::wstring& targetAppName = L""); 76 77 // Function to delete the shortcut control 78 static void ShortcutControl::DeleteShortcutControl(StackPanel& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, int index); 79 80 // Function to get the shortcut type 81 static ShortcutType GetShortcutType(const Controls::ComboBox& typeCombo); 82 83 // Function to remove extra quotes from the start and end of the string (used where we will add them as needed later) 84 static std::wstring ShortcutControl::RemoveExtraQuotes(const std::wstring& str); 85 86 // Function to return the stack panel element of the ShortcutControl. This is the externally visible UI element which can be used to add it to other layouts 87 StackPanel GetShortcutControl(); 88 89 // Function to create the detect shortcut UI window 90 static void CreateDetectShortcutWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, KBMEditor::KeyboardManagerState& keyboardManagerState, const int colIndex, StackPanel table, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, StackPanel controlLayout, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, HWND parentWindow, RemapBuffer& remapBuffer); 91 }; 92 93 StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut& shortCut, winrt::Windows::UI::Xaml::Thickness& textInputMargin, ::StackPanel& _controlStackPanel); 94 95 void CreateNewTempShortcut(StackPanel& row, Shortcut& tempShortcut, const uint32_t& rowIndex); 96 97 StackPanel SetupOpenURIControls(StackPanel& parent, StackPanel& row, Shortcut& shortCut, winrt::Windows::UI::Xaml::Thickness& textInputMargin, ::StackPanel& _controlStackPanel);