#include "pch.h" #include "SingleKeyRemapControl.h" #include "keyboardmanager/common/Helpers.h" //Both static members are initialized to null HWND SingleKeyRemapControl::EditKeyboardWindowHandle = nullptr; KeyboardManagerState* SingleKeyRemapControl::keyboardManagerState = nullptr; // Initialized as new vector std::vector> SingleKeyRemapControl::singleKeyRemapBuffer; // 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. void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector>>& keyboardRemapControlObjects, const DWORD originalKey, const DWORD newKey) { // Create new SingleKeyRemapControl objects dynamically so that we does not get destructed std::vector> newrow; newrow.push_back(std::move(std::unique_ptr(new SingleKeyRemapControl(parent, 0)))); newrow.push_back(std::move(std::unique_ptr(new SingleKeyRemapControl(parent, 1)))); keyboardRemapControlObjects.push_back(std::move(newrow)); // Add to grid parent.RowDefinitions().Append(RowDefinition()); parent.SetColumn(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->getSingleKeyRemapControl(), KeyboardManagerConstants::RemapTableOriginalColIndex); parent.SetRow(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->getSingleKeyRemapControl(), parent.RowDefinitions().Size() - 1); parent.SetColumn(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl(), KeyboardManagerConstants::RemapTableNewColIndex); parent.SetRow(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl(), parent.RowDefinitions().Size() - 1); // SingleKeyRemapControl for the original key. parent.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->getSingleKeyRemapControl()); // Arrow icon FontIcon arrowIcon; arrowIcon.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets")); arrowIcon.Glyph(L"\xE72A"); arrowIcon.VerticalAlignment(VerticalAlignment::Center); arrowIcon.HorizontalAlignment(HorizontalAlignment::Center); parent.SetColumn(arrowIcon, KeyboardManagerConstants::RemapTableArrowColIndex); parent.SetRow(arrowIcon, parent.RowDefinitions().Size() - 1); parent.Children().Append(arrowIcon); // SingleKeyRemapControl for the new remap key parent.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl()); // Set the key text if the two keys are not null (i.e. default args) if (originalKey != NULL && newKey != NULL) { singleKeyRemapBuffer.push_back(std::vector{ originalKey, newKey }); std::vector keyCodes = keyboardManagerState->keyboardMap.GetKeyCodeList(); auto it = std::find(keyCodes.begin(), keyCodes.end(), originalKey); if (it != keyCodes.end()) { keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->singleKeyRemapDropDown.SetSelectedIndex((int32_t)std::distance(keyCodes.begin(), it)); } it = std::find(keyCodes.begin(), keyCodes.end(), newKey); if (it != keyCodes.end()) { keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->singleKeyRemapDropDown.SetSelectedIndex((int32_t)std::distance(keyCodes.begin(), it)); } } else { // Initialize both keys to NULL singleKeyRemapBuffer.push_back(std::vector{ NULL, NULL }); } // Delete row button Windows::UI::Xaml::Controls::Button deleteRemapKeys; FontIcon deleteSymbol; deleteSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets")); deleteSymbol.Glyph(L"\xE74D"); deleteRemapKeys.Content(deleteSymbol); deleteRemapKeys.Background(Media::SolidColorBrush(Colors::Transparent())); deleteRemapKeys.HorizontalAlignment(HorizontalAlignment::Center); deleteRemapKeys.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) { Button currentButton = sender.as