/ src / modules / keyboardmanager / KeyboardManagerEditorLibrary / SingleKeyRemapControl.h
SingleKeyRemapControl.h
 1  #pragma once
 2  
 3  #include <keyboardmanager/common/Shortcut.h>
 4  
 5  #include <KeyDropDownControl.h>
 6  
 7  namespace KBMEditor
 8  {
 9      class KeyboardManagerState;
10  }
11  
12  namespace winrt::Windows::UI::Xaml
13  {
14      struct XamlRoot;
15      namespace Controls
16      {
17          struct StackPanel;
18          struct Grid;
19          struct Button;
20      }
21  }
22  
23  class SingleKeyRemapControl
24  {
25  private:
26      // Button to type the remap key
27      winrt::Windows::Foundation::IInspectable typeKey;
28  
29      // StackPanel to parent the above controls
30      winrt::Windows::Foundation::IInspectable singleKeyRemapControlLayout;
31  
32      // Stack panel for the drop downs to display the selected shortcut for the hybrid case
33      winrt::Windows::Foundation::IInspectable hybridDropDownVariableSizedWrapGrid;
34  
35      // Function to set the accessible names for all the controls in a row
36      static void UpdateAccessibleNames(StackPanel sourceColumn, StackPanel mappedToColumn, Button deleteButton, int rowIndex);
37  
38      void TextToMapChangedHandler(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e);
39  
40  public:
41      // Vector to store dynamically allocated KeyDropDownControl objects to avoid early destruction
42      std::vector<std::unique_ptr<KeyDropDownControl>> keyDropDownControlObjects;
43  
44      // Handle to the current Edit Keyboard Window
45      static HWND EditKeyboardWindowHandle;
46  
47      // Pointer to the keyboard manager state
48      static KBMEditor::KeyboardManagerState* keyboardManagerState;
49  
50      // Stores the current list of remappings
51      static RemapBuffer singleKeyRemapBuffer;
52  
53      // constructor
54      SingleKeyRemapControl(StackPanel table, StackPanel row, const int colIndex);
55  
56      // Function to add a new row to the remap keys table. If the originalKey and newKey args are provided, then the displayed remap keys are set to those values.
57      static void AddNewControlKeyRemapRow(StackPanel& parent, std::vector<std::vector<std::unique_ptr<SingleKeyRemapControl>>>& keyboardRemapControlObjects, const DWORD originalKey = 0, const KeyShortcutTextUnion newKey = (DWORD)0);
58  
59      // Function to return the stack panel element of the SingleKeyRemapControl. This is the externally visible UI element which can be used to add it to other layouts
60      winrt::Windows::UI::Xaml::Controls::StackPanel getSingleKeyRemapControl();
61  
62      // Function to create the detect remap keys UI window
63      void createDetectKeyWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, KBMEditor::KeyboardManagerState& keyboardManagerState);
64  };