From 8a1d2611d8fafc0a1d39485a4294e7e60754e2d8 Mon Sep 17 00:00:00 2001 From: Mykhailo Pylyp Date: Fri, 6 Nov 2020 16:24:11 +0200 Subject: [PATCH] [KBM] Added banded rows (#7787) * Added banded rows * Fix build after merge * accessibility names, capturing static row indexes by lambda * Fix position of targetApp textbox * fix wrong path for textbox --- .../keyboardmanager/common/Helpers.cpp | 8 + src/modules/keyboardmanager/common/Helpers.h | 2 + .../common/KeyboardManagerConstants.h | 7 +- .../keyboardmanager/ui/EditKeyboardWindow.cpp | 36 +---- .../ui/EditShortcutsWindow.cpp | 48 ++---- .../keyboardmanager/ui/KeyDropDownControl.cpp | 67 ++++---- .../keyboardmanager/ui/KeyDropDownControl.h | 15 +- .../keyboardmanager/ui/ShortcutControl.cpp | 151 ++++++++---------- .../keyboardmanager/ui/ShortcutControl.h | 7 +- .../ui/SingleKeyRemapControl.cpp | 108 ++++++------- .../ui/SingleKeyRemapControl.h | 4 +- src/modules/keyboardmanager/ui/UIHelpers.cpp | 4 +- src/modules/keyboardmanager/ui/UIHelpers.h | 2 +- 13 files changed, 196 insertions(+), 263 deletions(-) diff --git a/src/modules/keyboardmanager/common/Helpers.cpp b/src/modules/keyboardmanager/common/Helpers.cpp index ee8483848f..97b91cfece 100644 --- a/src/modules/keyboardmanager/common/Helpers.cpp +++ b/src/modules/keyboardmanager/common/Helpers.cpp @@ -360,4 +360,12 @@ namespace KeyboardManagerHelper // If we have at least two keys equal to 'selectedKeyCode' than modifier was repeated return numberOfSameType > 1; } + + winrt::Windows::Foundation::IInspectable GetWrapped(const winrt::Windows::Foundation::IInspectable& element, double width) + { + StackPanel sp = StackPanel(); + sp.Width(width); + sp.Children().Append(element.as()); + return sp; + } } diff --git a/src/modules/keyboardmanager/common/Helpers.h b/src/modules/keyboardmanager/common/Helpers.h index 0bd550f246..c11bb07f9e 100644 --- a/src/modules/keyboardmanager/common/Helpers.h +++ b/src/modules/keyboardmanager/common/Helpers.h @@ -107,4 +107,6 @@ namespace KeyboardManagerHelper // Function to check if a modifier has been repeated in the previous drop downs bool CheckRepeatedModifier(const std::vector& currentKeys, int selectedKeyCodes); + + winrt::Windows::Foundation::IInspectable GetWrapped(const winrt::Windows::Foundation::IInspectable& element, double width); } \ No newline at end of file diff --git a/src/modules/keyboardmanager/common/KeyboardManagerConstants.h b/src/modules/keyboardmanager/common/KeyboardManagerConstants.h index cd655179e0..8d475230bb 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerConstants.h +++ b/src/modules/keyboardmanager/common/KeyboardManagerConstants.h @@ -79,15 +79,18 @@ namespace KeyboardManagerConstants inline const long ShortcutTableNewColIndex = 2; inline const long ShortcutTableTargetAppColIndex = 3; inline const long ShortcutTableRemoveColIndex = 4; + inline const long ShortcutArrowColumnWidth = 90; inline const DWORD64 ShortcutTableDropDownWidth = 110; inline const DWORD64 ShortcutTableDropDownSpacing = 10; + inline const long ShortcutOriginColumnWidth = 3 * ShortcutTableDropDownWidth + 2 * ShortcutTableDropDownSpacing; + inline const long ShortcutTargetColumnWidth = 3 * ShortcutTableDropDownWidth + 2 * ShortcutTableDropDownSpacing + 25; // Drop down height used for both Edit Keyboard and Edit Shortcuts inline const DWORD64 TableDropDownHeight = 200; - inline const DWORD64 TableArrowColWidth = 20; + inline const DWORD64 TableArrowColWidth = 230; inline const DWORD64 TableRemoveColWidth = 20; inline const DWORD64 TableWarningColWidth = 20; - inline const DWORD64 TableTargetAppColWidth = ShortcutTableDropDownWidth + 50; + inline const DWORD64 TableTargetAppColWidth = ShortcutTableDropDownWidth + TableRemoveColWidth * 2; // Shared style constants for both Remap Table and Shortcut Table inline const DWORD64 HeaderButtonWidth = 100; diff --git a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp index 1c19d2d57c..f83adb022d 100644 --- a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp @@ -199,45 +199,24 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan keyRemapInfoExample.TextWrapping(TextWrapping::Wrap); // Table to display the key remaps - Grid keyRemapTable; - ColumnDefinition originalColumn; - originalColumn.MinWidth(KeyboardManagerConstants::RemapTableDropDownWidth); - originalColumn.MaxWidth(KeyboardManagerConstants::RemapTableDropDownWidth); - ColumnDefinition arrowColumn; - arrowColumn.MinWidth(KeyboardManagerConstants::TableArrowColWidth); - ColumnDefinition newColumn; - newColumn.MinWidth(3 * KeyboardManagerConstants::ShortcutTableDropDownWidth + 2 * KeyboardManagerConstants::ShortcutTableDropDownSpacing); - newColumn.MaxWidth(3 * KeyboardManagerConstants::ShortcutTableDropDownWidth + 2 * KeyboardManagerConstants::ShortcutTableDropDownSpacing); - ColumnDefinition removeColumn; - removeColumn.MinWidth(KeyboardManagerConstants::TableRemoveColWidth); - keyRemapTable.Margin({ 10, 10, 10, 20 }); - keyRemapTable.HorizontalAlignment(HorizontalAlignment::Stretch); - keyRemapTable.ColumnDefinitions().Append(originalColumn); - keyRemapTable.ColumnDefinitions().Append(arrowColumn); - keyRemapTable.ColumnDefinitions().Append(newColumn); - keyRemapTable.ColumnDefinitions().Append(removeColumn); - keyRemapTable.RowDefinitions().Append(RowDefinition()); - keyRemapTable.MinWidth(KeyboardManagerConstants::EditKeyboardTableMinWidth); + StackPanel keyRemapTable; // First header textblock in the header row of the keys remap table TextBlock originalKeyRemapHeader; originalKeyRemapHeader.Text(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_SOURCEHEADER)); originalKeyRemapHeader.FontWeight(Text::FontWeights::Bold()); - originalKeyRemapHeader.Margin({ 0, 0, 0, 10 }); + StackPanel originalKeyHeaderContainer = KeyboardManagerHelper::GetWrapped(originalKeyRemapHeader, KeyboardManagerConstants::RemapTableDropDownWidth + KeyboardManagerConstants::TableArrowColWidth).as(); // Second header textblock in the header row of the keys remap table TextBlock newKeyRemapHeader; newKeyRemapHeader.Text(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_TARGETHEADER)); newKeyRemapHeader.FontWeight(Text::FontWeights::Bold()); - newKeyRemapHeader.Margin({ 0, 0, 0, 10 }); - keyRemapTable.SetColumn(originalKeyRemapHeader, KeyboardManagerConstants::RemapTableOriginalColIndex); - keyRemapTable.SetRow(originalKeyRemapHeader, 0); - keyRemapTable.SetColumn(newKeyRemapHeader, KeyboardManagerConstants::RemapTableNewColIndex); - keyRemapTable.SetRow(newKeyRemapHeader, 0); - - keyRemapTable.Children().Append(originalKeyRemapHeader); - keyRemapTable.Children().Append(newKeyRemapHeader); + StackPanel tableHeader = StackPanel(); + tableHeader.Orientation(Orientation::Horizontal); + tableHeader.Margin({ 10, 0, 0, 10 }); + tableHeader.Children().Append(originalKeyHeaderContainer); + tableHeader.Children().Append(newKeyRemapHeader); // Store handle of edit keyboard window SingleKeyRemapControl::EditKeyboardWindowHandle = _hWndEditKeyboardWindow; @@ -328,6 +307,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan // Remapping table StackPanel mappingsPanel; + mappingsPanel.Children().Append(tableHeader); mappingsPanel.Children().Append(keyRemapTable); mappingsPanel.Children().Append(addRemapKey); diff --git a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp index 3d48059300..333aab3043 100644 --- a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp @@ -158,60 +158,33 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa shortcutRemapInfoExample.TextWrapping(TextWrapping::Wrap); // Table to display the shortcuts - Windows::UI::Xaml::Controls::Grid shortcutTable; - Grid keyRemapTable; - ColumnDefinition originalColumn; - originalColumn.MinWidth(3 * KeyboardManagerConstants::ShortcutTableDropDownWidth + 2 * KeyboardManagerConstants::ShortcutTableDropDownSpacing); - originalColumn.MaxWidth(3 * KeyboardManagerConstants::ShortcutTableDropDownWidth + 2 * KeyboardManagerConstants::ShortcutTableDropDownSpacing); - ColumnDefinition arrowColumn; - arrowColumn.MinWidth(KeyboardManagerConstants::TableArrowColWidth); - ColumnDefinition newColumn; - newColumn.MinWidth(3 * KeyboardManagerConstants::ShortcutTableDropDownWidth + 2 * KeyboardManagerConstants::ShortcutTableDropDownSpacing); - newColumn.MaxWidth(3 * KeyboardManagerConstants::ShortcutTableDropDownWidth + 2 * KeyboardManagerConstants::ShortcutTableDropDownSpacing); - ColumnDefinition targetAppColumn; - targetAppColumn.MinWidth(KeyboardManagerConstants::TableTargetAppColWidth); - ColumnDefinition removeColumn; - removeColumn.MinWidth(KeyboardManagerConstants::TableRemoveColWidth); - shortcutTable.Margin({ 10, 10, 10, 20 }); - shortcutTable.HorizontalAlignment(HorizontalAlignment::Stretch); - shortcutTable.ColumnDefinitions().Append(originalColumn); - shortcutTable.ColumnDefinitions().Append(arrowColumn); - shortcutTable.ColumnDefinitions().Append(newColumn); - shortcutTable.ColumnDefinitions().Append(targetAppColumn); - shortcutTable.ColumnDefinitions().Append(removeColumn); - shortcutTable.RowDefinitions().Append(RowDefinition()); - shortcutTable.MinWidth(KeyboardManagerConstants::EditShortcutsTableMinWidth); + StackPanel shortcutTable; // First header textblock in the header row of the shortcut table TextBlock originalShortcutHeader; originalShortcutHeader.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_SOURCEHEADER)); originalShortcutHeader.FontWeight(Text::FontWeights::Bold()); - originalShortcutHeader.Margin({ 0, 0, 0, 10 }); // Second header textblock in the header row of the shortcut table TextBlock newShortcutHeader; newShortcutHeader.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_TARGETHEADER)); newShortcutHeader.FontWeight(Text::FontWeights::Bold()); - newShortcutHeader.Margin({ 0, 0, 0, 10 }); // Third header textblock in the header row of the shortcut table TextBlock targetAppHeader; targetAppHeader.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_TARGETAPPHEADER)); targetAppHeader.Width(KeyboardManagerConstants::ShortcutTableDropDownWidth); targetAppHeader.FontWeight(Text::FontWeights::Bold()); - targetAppHeader.Margin({ 0, 0, 0, 10 }); targetAppHeader.HorizontalAlignment(HorizontalAlignment::Center); - shortcutTable.SetColumn(originalShortcutHeader, KeyboardManagerConstants::ShortcutTableOriginalColIndex); - shortcutTable.SetRow(originalShortcutHeader, 0); - shortcutTable.SetColumn(newShortcutHeader, KeyboardManagerConstants::ShortcutTableNewColIndex); - shortcutTable.SetRow(newShortcutHeader, 0); - shortcutTable.SetColumn(targetAppHeader, KeyboardManagerConstants::ShortcutTableTargetAppColIndex); - shortcutTable.SetRow(targetAppHeader, 0); - - shortcutTable.Children().Append(originalShortcutHeader); - shortcutTable.Children().Append(newShortcutHeader); - shortcutTable.Children().Append(targetAppHeader); + StackPanel tableHeader = StackPanel(); + tableHeader.Orientation(Orientation::Horizontal); + tableHeader.Margin({ 10, 0, 0, 10 }); + auto originalShortcutContainer = KeyboardManagerHelper::GetWrapped(originalShortcutHeader, KeyboardManagerConstants::ShortcutOriginColumnWidth + (double)KeyboardManagerConstants::ShortcutArrowColumnWidth); + tableHeader.Children().Append(originalShortcutContainer.as()); + auto newShortcutHeaderContainer = KeyboardManagerHelper::GetWrapped(newShortcutHeader, KeyboardManagerConstants::ShortcutTargetColumnWidth); + tableHeader.Children().Append(newShortcutHeaderContainer.as()); + tableHeader.Children().Append(targetAppHeader); // Store handle of edit shortcuts window ShortcutControl::EditShortcutsWindowHandle = _hWndEditShortcutsWindow; @@ -289,7 +262,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa plusSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets")); plusSymbol.Glyph(L"\xE109"); addShortcut.Content(plusSymbol); - addShortcut.Margin({ 10, 0, 0, 25 }); + addShortcut.Margin({ 10, 10, 0, 25 }); addShortcut.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) { ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects); @@ -315,6 +288,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa // Remapping table StackPanel mappingsPanel; + mappingsPanel.Children().Append(tableHeader); mappingsPanel.Children().Append(shortcutTable); mappingsPanel.Children().Append(addShortcut); diff --git a/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp b/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp index 73bf264839..7feb8f5a3c 100644 --- a/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp +++ b/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp @@ -100,29 +100,25 @@ void KeyDropDownControl::CheckAndUpdateKeyboardLayout(ComboBox currentDropDown, } // 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 -void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyControl, int colIndex, RemapBuffer& singleKeyRemapBuffer) +void KeyDropDownControl::SetSelectionHandler(StackPanel& table, StackPanel row, int colIndex, RemapBuffer& singleKeyRemapBuffer) { // drop down selection handler - auto onSelectionChange = [&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender) { + auto onSelectionChange = [&, table, row, colIndex](winrt::Windows::Foundation::IInspectable const& sender) { + uint32_t rowIndex = -1; + if (!table.Children().IndexOf(row, rowIndex)) + { + return; + } + ComboBox currentDropDown = sender.as(); int selectedKeyCode = GetSelectedValue(currentDropDown); + // Validate current remap selection + KeyboardManagerHelper::ErrorType errorType = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(rowIndex, colIndex, selectedKeyCode, singleKeyRemapBuffer); - // Get row index of the single key control - uint32_t controlIndex; - bool indexFound = table.Children().IndexOf(singleKeyControl, controlIndex); - if (indexFound) + // If there is an error set the warning flyout + if (errorType != KeyboardManagerHelper::ErrorType::NoError) { - // GetRow will give the row index including the table header - int rowIndex = table.GetRow(singleKeyControl) - 1; - - // Validate current remap selection - KeyboardManagerHelper::ErrorType errorType = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(rowIndex, colIndex, selectedKeyCode, singleKeyRemapBuffer); - - // If there is an error set the warning flyout - if (errorType != KeyboardManagerHelper::ErrorType::NoError) - { - SetDropDownError(currentDropDown, KeyboardManagerHelper::GetErrorMessage(errorType)); - } + SetDropDownError(currentDropDown, KeyboardManagerHelper::GetErrorMessage(errorType)); } }; @@ -141,22 +137,17 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyCo }); } -std::pair KeyDropDownControl::ValidateShortcutSelection(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow) +std::pair KeyDropDownControl::ValidateShortcutSelection(StackPanel table, StackPanel row, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow) { ComboBox currentDropDown = dropDown.as(); uint32_t dropDownIndex = -1; bool dropDownFound = parent.Children().IndexOf(currentDropDown, dropDownIndex); - // Get row index of the single key control - uint32_t controlIndex; - bool controlIindexFound = table.Children().IndexOf(shortcutControl, controlIndex); - int rowIndex = -1; std::pair validationResult = std::make_pair(KeyboardManagerHelper::ErrorType::NoError, BufferValidationHelpers::DropDownAction::NoAction); - + + uint32_t rowIndex; + bool controlIindexFound = table.Children().IndexOf(row, rowIndex); if (controlIindexFound) { - // GetRow will give the row index including the table header - rowIndex = table.GetRow(shortcutControl) - 1; - std::vector selectedCodes = GetSelectedCodesFromStackPanel(parent); std::wstring appName; @@ -171,7 +162,7 @@ std::pair KeyDropDownControl::ValidateSho // Add or clear unused drop downs if (validationResult.second == BufferValidationHelpers::DropDownAction::AddDropDown) { - AddDropDown(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); + AddDropDown(table, row, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); } else if (validationResult.second == BufferValidationHelpers::DropDownAction::ClearUnusedDropDowns) { @@ -224,10 +215,10 @@ std::pair KeyDropDownControl::ValidateSho } // Function to set selection handler for shortcut drop down. Needs to be called after the constructor since the shortcutControl StackPanel is null if called in the constructor -void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox& targetApp, bool isHybridControl, bool isSingleKeyWindow) +void KeyDropDownControl::SetSelectionHandler(StackPanel& table, StackPanel row, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox& targetApp, bool isHybridControl, bool isSingleKeyWindow) { - auto onSelectionChange = [&, table, shortcutControl, colIndex, parent, targetApp, isHybridControl, isSingleKeyWindow](winrt::Windows::Foundation::IInspectable const& sender) { - std::pair validationResult = ValidateShortcutSelection(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); + auto onSelectionChange = [&, table, row, colIndex, parent, targetApp, isHybridControl, isSingleKeyWindow](winrt::Windows::Foundation::IInspectable const& sender) { + std::pair validationResult = ValidateShortcutSelection(table, row, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); // Check if the drop down row index was identified from the return value of validateSelection if (validationResult.second != -1) @@ -236,7 +227,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel shortcutCon if (validationResult.first != KeyboardManagerHelper::ErrorType::NoError) { // Validate all the drop downs - ValidateShortcutFromDropDownList(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); + ValidateShortcutFromDropDownList(table, row, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); } // Reset the buffer based on the new selected drop down items. Use static key code list since the KeyDropDownControl object might be deleted @@ -312,11 +303,13 @@ ComboBox KeyDropDownControl::GetComboBox() } // Function to add a drop down to the shortcut stack panel -void KeyDropDownControl::AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning) +void KeyDropDownControl::AddDropDown(StackPanel& table, StackPanel row, StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning) { keyDropDownControlObjects.emplace_back(std::make_unique(true, ignoreWarning, colIndex == 1)); parent.Children().Append(keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->GetComboBox()); - keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->SetSelectionHandler(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); + uint32_t index; + bool found = table.Children().IndexOf(row, index); + keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->SetSelectionHandler(table, row, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); parent.UpdateLayout(); // Update accessible name @@ -339,7 +332,7 @@ std::vector KeyDropDownControl::GetSelectedCodesFromStackPanel(StackPan } // Function for validating the selection of shortcuts for all the associated drop downs -void KeyDropDownControl::ValidateShortcutFromDropDownList(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow) +void KeyDropDownControl::ValidateShortcutFromDropDownList(StackPanel table, StackPanel row, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow) { // Iterate over all drop downs from left to right in that row/col and validate if there is an error in any of the drop downs. After this the state should be error-free (if it is a valid shortcut) for (int i = 0; i < keyDropDownControlObjects.size(); i++) @@ -361,7 +354,7 @@ void KeyDropDownControl::ValidateShortcutFromDropDownList(Grid table, StackPanel // If the key/shortcut is valid and that drop down is not empty if (((currentShortcut.index() == 0 && std::get(currentShortcut) != NULL) || (currentShortcut.index() == 1 && std::get(currentShortcut).IsValidShortcut())) && GetSelectedValue(keyDropDownControlObjects[i]->GetComboBox()) != -1) { - keyDropDownControlObjects[i]->ValidateShortcutSelection(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); + keyDropDownControlObjects[i]->ValidateShortcutSelection(table, row, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow); } } } @@ -375,7 +368,7 @@ void KeyDropDownControl::SetDropDownError(ComboBox currentDropDown, hstring mess } // Function to add a shortcut to the UI control as combo boxes -void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, std::vector>& keyDropDownControlObjects, RemapBuffer& remapBuffer, StackPanel controlLayout, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow) +void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, StackPanel table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, std::vector>& keyDropDownControlObjects, RemapBuffer& remapBuffer, StackPanel row, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow) { // Delete the existing drop down menus parent.Children().Clear(); @@ -392,7 +385,7 @@ void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, Grid table, Sta ignoreWarning = true; } - KeyDropDownControl::AddDropDown(table, controlLayout, parent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow, ignoreWarning); + KeyDropDownControl::AddDropDown(table, row, parent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow, ignoreWarning); for (int i = 0; i < shortcutKeyCodes.size(); i++) { diff --git a/src/modules/keyboardmanager/ui/KeyDropDownControl.h b/src/modules/keyboardmanager/ui/KeyDropDownControl.h index 03b9d2f1b7..64b153c76d 100644 --- a/src/modules/keyboardmanager/ui/KeyDropDownControl.h +++ b/src/modules/keyboardmanager/ui/KeyDropDownControl.h @@ -13,7 +13,6 @@ namespace winrt::Windows namespace UI::Xaml::Controls { struct StackPanel; - struct Grid; struct ComboBox; struct Flyout; struct TextBlock; @@ -63,25 +62,25 @@ public: } // 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 - void SetSelectionHandler(winrt::Windows::UI::Xaml::Controls::Grid& table, winrt::Windows::UI::Xaml::Controls::StackPanel singleKeyControl, int colIndex, RemapBuffer& singleKeyRemapBuffer); + void SetSelectionHandler(StackPanel& table, StackPanel row, int colIndex, RemapBuffer& singleKeyRemapBuffer); // Function for validating the selection of shortcuts for the drop down - std::pair ValidateShortcutSelection(winrt::Windows::UI::Xaml::Controls::Grid table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); + std::pair ValidateShortcutSelection(StackPanel table, StackPanel row, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); - // Function to set selection handler for shortcut drop down. Needs to be called after the constructor since the shortcutControl StackPanel is null if called in the constructor - void SetSelectionHandler(winrt::Windows::UI::Xaml::Controls::Grid& table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp, bool isHybridControl, bool isSingleKeyWindow); + // Function to set selection handler for shortcut drop down. + void SetSelectionHandler(StackPanel& table, StackPanel row, winrt::Windows::UI::Xaml::Controls::StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp, bool isHybridControl, bool isSingleKeyWindow); // Function to return the combo box element of the drop down ComboBox GetComboBox(); // Function to add a drop down to the shortcut stack panel - static void AddDropDown(winrt::Windows::UI::Xaml::Controls::Grid table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning = false); + static void AddDropDown(StackPanel& table, StackPanel row, winrt::Windows::UI::Xaml::Controls::StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning = false); // Function to get the list of key codes from the shortcut combo box stack panel static std::vector GetSelectedCodesFromStackPanel(StackPanel parent); // Function for validating the selection of shortcuts for all the associated drop downs - static void ValidateShortcutFromDropDownList(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); + static void ValidateShortcutFromDropDownList(StackPanel table, StackPanel row, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); // Function to set the warning message void SetDropDownError(winrt::Windows::UI::Xaml::Controls::ComboBox currentDropDown, winrt::hstring message); @@ -90,7 +89,7 @@ public: void SetSelectedValue(std::wstring value); // Function to add a shortcut to the UI control as combo boxes - static void AddShortcutToControl(Shortcut shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, std::vector>& keyDropDownControlObjects, RemapBuffer& remapBuffer, StackPanel controlLayout, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); + static void AddShortcutToControl(Shortcut shortcut, StackPanel table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, std::vector>& keyDropDownControlObjects, RemapBuffer& remapBuffer, StackPanel row, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow); // Get keys name list depending if Disable is in dropdown static std::vector> GetKeyList(bool isShortcut, bool renderDisable); diff --git a/src/modules/keyboardmanager/ui/ShortcutControl.cpp b/src/modules/keyboardmanager/ui/ShortcutControl.cpp index 2e8137c705..8807013552 100644 --- a/src/modules/keyboardmanager/ui/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/ui/ShortcutControl.cpp @@ -14,7 +14,7 @@ KeyboardManagerState* ShortcutControl::keyboardManagerState = nullptr; // Initialized as new vector RemapBuffer ShortcutControl::shortcutRemapBuffer; -ShortcutControl::ShortcutControl(Grid table, const int colIndex, TextBox targetApp) +ShortcutControl::ShortcutControl(StackPanel table, StackPanel row, const int colIndex, TextBox targetApp) { shortcutDropDownStackPanel = StackPanel(); typeShortcut = Button(); @@ -26,20 +26,19 @@ ShortcutControl::ShortcutControl(Grid table, const int colIndex, TextBox targetA typeShortcut.as