From 6a9badd31ba69f6b9af58f4d0a77e7704b6fe511 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind <32061677+arjunbalgovind@users.noreply.github.com> Date: Mon, 13 Jul 2020 11:49:09 -0700 Subject: [PATCH] [Keyboard Manager] Cleanup header file references to improve incremental build time (#4880) * Remove WinUI include in KeyboardManagerState.h * Changed include steps * Clean up headers in KeyboardManagerUI except XamlBridge.h * Cleaned up headers in KeyboardManager common and test * Cleaned up headers in KeyboardManager project * Removed headers from XamlBridge * Removed some headers from kbm common pch * Added MP flag to reduce build time * Added missing include --- src/modules/keyboardmanager/common/Helpers.h | 16 +++++-- .../keyboardmanager/common/InputInterface.h | 2 - src/modules/keyboardmanager/common/KeyDelay.h | 2 +- .../common/KeyboardManagerCommon.vcxproj | 2 + .../common/KeyboardManagerState.cpp | 35 +++++++------- .../common/KeyboardManagerState.h | 29 +++++++----- .../keyboardmanager/common/Shortcut.cpp | 17 +++++++ src/modules/keyboardmanager/common/Shortcut.h | 23 ++++----- src/modules/keyboardmanager/common/pch.h | 10 +--- .../dll/KeyboardEventHandlers.cpp | 3 ++ .../dll/KeyboardEventHandlers.h | 12 +++-- .../dll/KeyboardManager.vcxproj | 2 + src/modules/keyboardmanager/dll/pch.h | 1 - .../test/KeyboardManagerTest.vcxproj | 2 + .../test/OSLevelShortcutRemappingTests.cpp | 1 + .../test/SingleKeyRemappingTests.cpp | 1 + .../keyboardmanager/test/TestHelpers.cpp | 2 + .../keyboardmanager/test/TestHelpers.h | 4 +- src/modules/keyboardmanager/test/pch.h | 6 +++ src/modules/keyboardmanager/ui/Dialog.cpp | 2 + src/modules/keyboardmanager/ui/Dialog.h | 16 +++++-- .../keyboardmanager/ui/EditKeyboardWindow.cpp | 4 +- .../keyboardmanager/ui/EditKeyboardWindow.h | 2 +- .../ui/EditShortcutsWindow.cpp | 1 + .../keyboardmanager/ui/EditShortcutsWindow.h | 4 +- .../keyboardmanager/ui/KeyDropDownControl.cpp | 41 +++++++++------- .../keyboardmanager/ui/KeyDropDownControl.h | 43 +++++++++++++---- .../ui/KeyboardManagerUI.vcxproj | 2 + .../keyboardmanager/ui/ShortcutControl.cpp | 43 +++++++++++++---- .../keyboardmanager/ui/ShortcutControl.h | 47 ++++++++----------- .../ui/SingleKeyRemapControl.cpp | 32 +++++++++++-- .../ui/SingleKeyRemapControl.h | 42 +++++++---------- src/modules/keyboardmanager/ui/Styles.cpp | 2 - src/modules/keyboardmanager/ui/Styles.h | 9 ++-- src/modules/keyboardmanager/ui/XamlBridge.cpp | 2 +- src/modules/keyboardmanager/ui/XamlBridge.h | 7 --- src/modules/keyboardmanager/ui/pch.h | 2 + 37 files changed, 291 insertions(+), 180 deletions(-) diff --git a/src/modules/keyboardmanager/common/Helpers.h b/src/modules/keyboardmanager/common/Helpers.h index 447d3920f6..7afbefacab 100644 --- a/src/modules/keyboardmanager/common/Helpers.h +++ b/src/modules/keyboardmanager/common/Helpers.h @@ -1,7 +1,17 @@ #pragma once -#include -#include -#include +namespace winrt +{ + struct hstring; + namespace Windows::Foundation + { + struct IInspectable; + namespace Collections + { + template + struct IVector; + } + } +} namespace KeyboardManagerHelper { diff --git a/src/modules/keyboardmanager/common/InputInterface.h b/src/modules/keyboardmanager/common/InputInterface.h index 9e358e0771..c54d5bde6b 100644 --- a/src/modules/keyboardmanager/common/InputInterface.h +++ b/src/modules/keyboardmanager/common/InputInterface.h @@ -1,6 +1,4 @@ #pragma once -#include "windows.h" -#include // Interface used to wrap keyboard input library methods class InputInterface diff --git a/src/modules/keyboardmanager/common/KeyDelay.h b/src/modules/keyboardmanager/common/KeyDelay.h index fd68ac971e..74774ce80f 100644 --- a/src/modules/keyboardmanager/common/KeyDelay.h +++ b/src/modules/keyboardmanager/common/KeyDelay.h @@ -1,9 +1,9 @@ #pragma once -#include #include #include #include #include +#include // Available states for the KeyDelay state machine. enum class KeyDelayState diff --git a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj index 34201ac968..df36ceb018 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj +++ b/src/modules/keyboardmanager/common/KeyboardManagerCommon.vcxproj @@ -99,6 +99,8 @@ Use pch.h + /MP %(AdditionalOptions) + /MP %(AdditionalOptions) shlwapi.lib; diff --git a/src/modules/keyboardmanager/common/KeyboardManagerState.cpp b/src/modules/keyboardmanager/common/KeyboardManagerState.cpp index fbf9d0d952..885eb498ba 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerState.cpp +++ b/src/modules/keyboardmanager/common/KeyboardManagerState.cpp @@ -1,5 +1,7 @@ #include "pch.h" #include "KeyboardManagerState.h" +#include <../common/settings_helpers.h> +#include "KeyDelay.h" // Constructor KeyboardManagerState::KeyboardManagerState() : @@ -179,15 +181,15 @@ bool KeyboardManagerState::AddAppSpecificShortcut(const std::wstring& app, const void KeyboardManagerState::ConfigureDetectShortcutUI(const StackPanel& textBlock1, const StackPanel& textBlock2) { std::lock_guard lock(currentShortcutUI_mutex); - currentShortcutUI1 = textBlock1; - currentShortcutUI2 = textBlock2; + currentShortcutUI1 = textBlock1.as(); + currentShortcutUI2 = textBlock2.as(); } // Function to set the textblock of the detect remap key UI so that it can be accessed by the hook void KeyboardManagerState::ConfigureDetectSingleKeyRemapUI(const StackPanel& textBlock) { std::lock_guard lock(currentSingleKeyUI_mutex); - currentSingleKeyUI = textBlock; + currentSingleKeyUI = textBlock.as(); } void KeyboardManagerState::AddKeyToLayout(const StackPanel& panel, const hstring& key) @@ -226,34 +228,34 @@ void KeyboardManagerState::UpdateDetectShortcutUI() detectedShortcut_lock.unlock(); // Since this function is invoked from the back-end thread, in order to update the UI the dispatcher must be used. - currentShortcutUI1.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this, detectedShortcutCopy]() { + currentShortcutUI1.as().Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this, detectedShortcutCopy]() { std::vector shortcut = detectedShortcutCopy.GetKeyVector(keyboardMap); - currentShortcutUI1.Children().Clear(); - currentShortcutUI2.Children().Clear(); + currentShortcutUI1.as().Children().Clear(); + currentShortcutUI2.as().Children().Clear(); // The second row should be hidden if there are 3 keys or lesser to avoid an extra margin if (shortcut.size() > 3) { - currentShortcutUI2.Visibility(Visibility::Visible); + currentShortcutUI2.as().Visibility(Visibility::Visible); } else { - currentShortcutUI2.Visibility(Visibility::Collapsed); + currentShortcutUI2.as().Visibility(Visibility::Collapsed); } for (int i = 0; i < shortcut.size(); i++) { if (i < 3) { - AddKeyToLayout(currentShortcutUI1, shortcut[i]); + AddKeyToLayout(currentShortcutUI1.as(), shortcut[i]); } else { - AddKeyToLayout(currentShortcutUI2, shortcut[i]); + AddKeyToLayout(currentShortcutUI2.as(), shortcut[i]); } } - currentShortcutUI1.UpdateLayout(); - currentShortcutUI2.UpdateLayout(); + currentShortcutUI1.as().UpdateLayout(); + currentShortcutUI2.as().UpdateLayout(); }); } @@ -265,13 +267,12 @@ void KeyboardManagerState::UpdateDetectSingleKeyRemapUI() { return; } - // Since this function is invoked from the back-end thread, in order to update the UI the dispatcher must be used. - currentSingleKeyUI.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this]() { - currentSingleKeyUI.Children().Clear(); + currentSingleKeyUI.as().Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this]() { + currentSingleKeyUI.as().Children().Clear(); hstring key = winrt::to_hstring(keyboardMap.GetKeyName(detectedRemapKey).c_str()); - AddKeyToLayout(currentSingleKeyUI, key); - currentSingleKeyUI.UpdateLayout(); + AddKeyToLayout(currentSingleKeyUI.as(), key); + currentSingleKeyUI.as().UpdateLayout(); }); } diff --git a/src/modules/keyboardmanager/common/KeyboardManagerState.h b/src/modules/keyboardmanager/common/KeyboardManagerState.h index d04a9be102..8f9b34610b 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerState.h +++ b/src/modules/keyboardmanager/common/KeyboardManagerState.h @@ -1,16 +1,19 @@ #pragma once #include "Helpers.h" -#include "../common/keyboard_layout.h" #include "Shortcut.h" #include "RemapShortcut.h" -#include "KeyDelay.h" -#include "KeyboardManagerConstants.h" -#include #include -#include -#include <../common/settings_helpers.h> +#include "KeyboardManagerConstants.h" +#include "../common/keyboard_layout.h" +#include +#include -using namespace winrt::Windows::UI::Xaml::Controls; +class KeyDelay; + +namespace winrt::Windows::UI::Xaml::Controls +{ + struct StackPanel; +} // Enum type to store different states of the UI enum class KeyboardManagerUIState @@ -52,12 +55,12 @@ private: std::mutex detectedRemapKey_mutex; // Stores the UI element which is to be updated based on the remap key entered. - StackPanel currentSingleKeyUI; + winrt::Windows::Foundation::IInspectable currentSingleKeyUI; std::mutex currentSingleKeyUI_mutex; // Stores the UI element which is to be updated based on the shortcut entered (each stackpanel represents a row of keys) - StackPanel currentShortcutUI1; - StackPanel currentShortcutUI2; + winrt::Windows::Foundation::IInspectable currentShortcutUI1; + winrt::Windows::Foundation::IInspectable currentShortcutUI2; std::mutex currentShortcutUI_mutex; // Stores the current configuration name. @@ -75,7 +78,7 @@ private: std::wstring activatedAppSpecificShortcutTarget; // Display a key by appending a border Control as a child of the panel. - void AddKeyToLayout(const StackPanel& panel, const winrt::hstring& key); + void AddKeyToLayout(const winrt::Windows::UI::Xaml::Controls::StackPanel& panel, const winrt::hstring& key); public: // The map members and their mutexes are left as public since the maps are used extensively in dllmain.cpp. @@ -136,10 +139,10 @@ public: bool AddAppSpecificShortcut(const std::wstring& app, const Shortcut& originalSC, const Shortcut& newSC); // Function to set the textblock of the detect shortcut UI so that it can be accessed by the hook - void ConfigureDetectShortcutUI(const StackPanel& textBlock1, const StackPanel& textBlock2); + void ConfigureDetectShortcutUI(const winrt::Windows::UI::Xaml::Controls::StackPanel& textBlock1, const winrt::Windows::UI::Xaml::Controls::StackPanel& textBlock2); // Function to set the textblock of the detect remap key UI so that it can be accessed by the hook - void ConfigureDetectSingleKeyRemapUI(const StackPanel& textBlock); + void ConfigureDetectSingleKeyRemapUI(const winrt::Windows::UI::Xaml::Controls::StackPanel& textBlock); // Function to update the detect shortcut UI based on the entered keys void UpdateDetectShortcutUI(); diff --git a/src/modules/keyboardmanager/common/Shortcut.cpp b/src/modules/keyboardmanager/common/Shortcut.cpp index 4b73191005..279ed94bf4 100644 --- a/src/modules/keyboardmanager/common/Shortcut.cpp +++ b/src/modules/keyboardmanager/common/Shortcut.cpp @@ -1,5 +1,22 @@ #include "pch.h" #include "Shortcut.h" +#include "../common/keyboard_layout.h" +#include "../common/shared_constants.h" +#include +#include "Helpers.h" +#include "InputInterface.h" + +// Constructor to initialize Shortcut from it's virtual key code string representation. +Shortcut::Shortcut(const std::wstring& shortcutVK) : + winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) +{ + auto keys = KeyboardManagerHelper::splitwstring(shortcutVK, ';'); + for (auto it : keys) + { + auto vkKeyCode = std::stoul(it); + SetKey(vkKeyCode); + } +} // Function to return the number of keys in the shortcut int Shortcut::Size() const diff --git a/src/modules/keyboardmanager/common/Shortcut.h b/src/modules/keyboardmanager/common/Shortcut.h index f7d748cfef..5e31fe6bf4 100644 --- a/src/modules/keyboardmanager/common/Shortcut.h +++ b/src/modules/keyboardmanager/common/Shortcut.h @@ -1,9 +1,11 @@ #pragma once -#include "Helpers.h" -#include "../common/keyboard_layout.h" -#include "../common/shared_constants.h" -#include -#include "InputInterface.h" + +class InputInterface; +class LayoutMap; +namespace KeyboardManagerHelper +{ + enum class ErrorType; +} // Enum type to store different states of the win key enum class ModifierKey @@ -31,16 +33,7 @@ public: } // Constructor to initialize Shortcut from it's virtual key code string representation. - Shortcut(const std::wstring& shortcutVK) : - winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL) - { - auto keys = KeyboardManagerHelper::splitwstring(shortcutVK, ';'); - for (auto it : keys) - { - auto vkKeyCode = std::stoul(it); - SetKey(vkKeyCode); - } - } + Shortcut(const std::wstring& shortcutVK); // == operator inline bool operator==(const Shortcut& sc) const diff --git a/src/modules/keyboardmanager/common/pch.h b/src/modules/keyboardmanager/common/pch.h index c333436bb8..0dd7c5e6e8 100644 --- a/src/modules/keyboardmanager/common/pch.h +++ b/src/modules/keyboardmanager/common/pch.h @@ -5,22 +5,14 @@ #include #include #include -#include -#include -#include -#include #include #include "winrt/Windows.Foundation.Numerics.h" -#include "winrt/Windows.UI.Xaml.Controls.Primitives.h" -#include "winrt/Windows.UI.Text.h" +#include #include "winrt/Windows.UI.Core.h" #include #include using namespace winrt; -using namespace Windows::UI; -using namespace Windows::UI::Composition; -using namespace Windows::UI::Xaml::Hosting; using namespace Windows::Foundation::Numerics; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Controls; \ No newline at end of file diff --git a/src/modules/keyboardmanager/dll/KeyboardEventHandlers.cpp b/src/modules/keyboardmanager/dll/KeyboardEventHandlers.cpp index 2dca529ada..12090ee27a 100644 --- a/src/modules/keyboardmanager/dll/KeyboardEventHandlers.cpp +++ b/src/modules/keyboardmanager/dll/KeyboardEventHandlers.cpp @@ -1,5 +1,8 @@ #include "pch.h" #include "KeyboardEventHandlers.h" +#include "../common/shared_constants.h" +#include +#include namespace KeyboardEventHandlers { diff --git a/src/modules/keyboardmanager/dll/KeyboardEventHandlers.h b/src/modules/keyboardmanager/dll/KeyboardEventHandlers.h index bd6450ccc3..d187837d29 100644 --- a/src/modules/keyboardmanager/dll/KeyboardEventHandlers.h +++ b/src/modules/keyboardmanager/dll/KeyboardEventHandlers.h @@ -1,7 +1,13 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include "keyboardmanager/common/KeyboardManagerConstants.h" + +class InputInterface; +class KeyboardManagerState; +class Shortcut; +class RemapShortcut; namespace KeyboardEventHandlers { diff --git a/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj b/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj index c1a946557c..9015f68a43 100644 --- a/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj +++ b/src/modules/keyboardmanager/dll/KeyboardManager.vcxproj @@ -108,6 +108,8 @@ Use pch.h + /MP %(AdditionalOptions) + /MP %(AdditionalOptions) diff --git a/src/modules/keyboardmanager/dll/pch.h b/src/modules/keyboardmanager/dll/pch.h index 8911a297e3..71811d444c 100644 --- a/src/modules/keyboardmanager/dll/pch.h +++ b/src/modules/keyboardmanager/dll/pch.h @@ -1,7 +1,6 @@ #pragma once #define WIN32_LEAN_AND_MEAN #include -#include #include #include #include diff --git a/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj b/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj index 8821633ec6..48d63ca4be 100644 --- a/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj +++ b/src/modules/keyboardmanager/test/KeyboardManagerTest.vcxproj @@ -99,6 +99,8 @@ Use pch.h + /MP %(AdditionalOptions) + /MP %(AdditionalOptions) diff --git a/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp b/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp index a270f7bd54..4badba573a 100644 --- a/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp +++ b/src/modules/keyboardmanager/test/OSLevelShortcutRemappingTests.cpp @@ -4,6 +4,7 @@ #include #include #include "TestHelpers.h" +#include "../common/shared_constants.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; diff --git a/src/modules/keyboardmanager/test/SingleKeyRemappingTests.cpp b/src/modules/keyboardmanager/test/SingleKeyRemappingTests.cpp index a244ec23c4..419a070a62 100644 --- a/src/modules/keyboardmanager/test/SingleKeyRemappingTests.cpp +++ b/src/modules/keyboardmanager/test/SingleKeyRemappingTests.cpp @@ -4,6 +4,7 @@ #include #include #include "TestHelpers.h" +#include "../common/shared_constants.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; diff --git a/src/modules/keyboardmanager/test/TestHelpers.cpp b/src/modules/keyboardmanager/test/TestHelpers.cpp index 05216b5e31..501280be59 100644 --- a/src/modules/keyboardmanager/test/TestHelpers.cpp +++ b/src/modules/keyboardmanager/test/TestHelpers.cpp @@ -1,5 +1,7 @@ #include "pch.h" #include "TestHelpers.h" +#include "MockedInput.h" +#include "keyboardmanager/common/KeyboardManagerState.h" namespace TestHelpers { diff --git a/src/modules/keyboardmanager/test/TestHelpers.h b/src/modules/keyboardmanager/test/TestHelpers.h index 30bf770c56..3aaf70e384 100644 --- a/src/modules/keyboardmanager/test/TestHelpers.h +++ b/src/modules/keyboardmanager/test/TestHelpers.h @@ -1,6 +1,6 @@ #pragma once -#include "MockedInput.h" -#include +class MockedInput; +class KeyboardManagerState; namespace TestHelpers { diff --git a/src/modules/keyboardmanager/test/pch.h b/src/modules/keyboardmanager/test/pch.h index 0a2f9ed9c5..5cec681826 100644 --- a/src/modules/keyboardmanager/test/pch.h +++ b/src/modules/keyboardmanager/test/pch.h @@ -1,2 +1,8 @@ #pragma once #pragma comment(lib, "shlwapi.lib") +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include diff --git a/src/modules/keyboardmanager/ui/Dialog.cpp b/src/modules/keyboardmanager/ui/Dialog.cpp index 0e8e6e0bf9..21400a2233 100644 --- a/src/modules/keyboardmanager/ui/Dialog.cpp +++ b/src/modules/keyboardmanager/ui/Dialog.cpp @@ -1,6 +1,8 @@ #include "pch.h" #include "Dialog.h" +using namespace winrt::Windows::Foundation; + IAsyncOperation Dialog::PartialRemappingConfirmationDialog(XamlRoot root, std::wstring dialogTitle) { ContentDialog confirmationDialog; diff --git a/src/modules/keyboardmanager/ui/Dialog.h b/src/modules/keyboardmanager/ui/Dialog.h index 9e683c596e..9ae81cc24f 100644 --- a/src/modules/keyboardmanager/ui/Dialog.h +++ b/src/modules/keyboardmanager/ui/Dialog.h @@ -3,9 +3,19 @@ #include #include #include -#include -using namespace winrt::Windows::Foundation; +namespace winrt::Windows::UI::Xaml +{ + namespace Foundation + { + template + struct IAsyncOperation; + } + namespace UI::Xaml + { + struct XamlRoot; + } +} namespace Dialog { @@ -37,5 +47,5 @@ namespace Dialog return isSuccess; } - IAsyncOperation PartialRemappingConfirmationDialog(winrt::Windows::UI::Xaml::XamlRoot root, std::wstring dialogTitle); + winrt::Windows::Foundation::IAsyncOperation PartialRemappingConfirmationDialog(winrt::Windows::UI::Xaml::XamlRoot root, std::wstring dialogTitle); }; diff --git a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp index ead11bec1e..0026314185 100644 --- a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp @@ -11,6 +11,8 @@ #include "Styles.h" #include "Dialog.h" #include +#include "../common/shared_constants.h" +#include "keyboardmanager/common/KeyboardManagerState.h" using namespace winrt::Windows::Foundation; @@ -397,7 +399,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan // Add remap key button Windows::UI::Xaml::Controls::Button addRemapKey; FontIcon plusSymbol; - plusSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets")); + plusSymbol.FontFamily(Media::FontFamily(L"Segoe MDL2 Assets")); plusSymbol.Glyph(L"\xE109"); addRemapKey.Content(plusSymbol); addRemapKey.Margin({ 10, 0, 0, 25 }); diff --git a/src/modules/keyboardmanager/ui/EditKeyboardWindow.h b/src/modules/keyboardmanager/ui/EditKeyboardWindow.h index 08533244d6..260b0f78ab 100644 --- a/src/modules/keyboardmanager/ui/EditKeyboardWindow.h +++ b/src/modules/keyboardmanager/ui/EditKeyboardWindow.h @@ -1,5 +1,5 @@ #pragma once -#include +class KeyboardManagerState; // Function to create the Edit Keyboard Window void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState); diff --git a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp index c076669456..2fd5f4a5bb 100644 --- a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp @@ -10,6 +10,7 @@ #include "Styles.h" #include "Dialog.h" #include +#include using namespace winrt::Windows::Foundation; diff --git a/src/modules/keyboardmanager/ui/EditShortcutsWindow.h b/src/modules/keyboardmanager/ui/EditShortcutsWindow.h index beead96101..d333134354 100644 --- a/src/modules/keyboardmanager/ui/EditShortcutsWindow.h +++ b/src/modules/keyboardmanager/ui/EditShortcutsWindow.h @@ -1,7 +1,5 @@ #pragma once -#include "keyboardmanager/common/KeyboardManagerState.h" -#include "keyboardmanager/common/Shortcut.h" -#include "keyboardmanager/common/Helpers.h" +class KeyboardManagerState; // Function to create the Edit Shortcuts Window void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState); diff --git a/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp b/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp index 034ef03bbe..9d9a653e32 100644 --- a/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp +++ b/src/modules/keyboardmanager/ui/KeyDropDownControl.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "KeyDropDownControl.h" #include "keyboardmanager/common/Helpers.h" +#include // Initialized to null KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr; @@ -8,28 +9,32 @@ KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr; // Function to set properties apart from the SelectionChanged event handler void KeyDropDownControl::SetDefaultProperties(bool isShortcut) { + dropDown = ComboBox(); + warningFlyout = Flyout(); + warningMessage = TextBlock(); + if (!isShortcut) { - dropDown.Width(KeyboardManagerConstants::RemapTableDropDownWidth); + dropDown.as().Width(KeyboardManagerConstants::RemapTableDropDownWidth); } else { - dropDown.Width(KeyboardManagerConstants::ShortcutTableDropDownWidth); + dropDown.as().Width(KeyboardManagerConstants::ShortcutTableDropDownWidth); } - dropDown.MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight); + dropDown.as().MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight); // Initialise layout attribute previousLayout = GetKeyboardLayout(0); keyCodeList = keyboardManagerState->keyboardMap.GetKeyCodeList(isShortcut); - dropDown.ItemsSource(KeyboardManagerHelper::ToBoxValue(keyboardManagerState->keyboardMap.GetKeyNameList(isShortcut))); + dropDown.as().ItemsSource(KeyboardManagerHelper::ToBoxValue(keyboardManagerState->keyboardMap.GetKeyNameList(isShortcut))); // drop down open handler - to reload the items with the latest layout - dropDown.DropDownOpened([&, isShortcut](winrt::Windows::Foundation::IInspectable const& sender, auto args) { + dropDown.as().DropDownOpened([&, isShortcut](winrt::Windows::Foundation::IInspectable const& sender, auto args) { ComboBox currentDropDown = sender.as(); CheckAndUpdateKeyboardLayout(currentDropDown, isShortcut); }); // Attach flyout to the drop down - warningFlyout.Content(warningMessage); - dropDown.ContextFlyout().SetAttachedFlyout((FrameworkElement)dropDown, warningFlyout); + warningFlyout.as().Content(warningMessage.as()); + dropDown.as().ContextFlyout().SetAttachedFlyout((FrameworkElement)dropDown.as(), warningFlyout.as()); } // Function to check if the layout has changed and accordingly update the drop down list @@ -48,7 +53,7 @@ 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, std::vector>& singleKeyRemapBuffer) +void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyControl, int colIndex, std::vector>& singleKeyRemapBuffer) { // drop down selection handler auto onSelectionChange = [&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender) { @@ -111,12 +116,12 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyC }; // Rather than on every selection change (which gets triggered on searching as well) we set the handler only when the drop down is closed - dropDown.DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) { + dropDown.as().DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) { onSelectionChange(sender); }); // We check if the selection changed was triggered while the drop down was closed. This is required to handle Type key, initial loading of remaps and if the user just types in the combo box without opening it - dropDown.SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) { + dropDown.as().SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) { ComboBox currentDropDown = sender.as(); if (!currentDropDown.IsDropDownOpen()) { @@ -127,7 +132,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyC std::pair KeyDropDownControl::ValidateShortcutSelection(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp) { - ComboBox currentDropDown = dropDown; + ComboBox currentDropDown = dropDown.as(); int selectedKeyIndex = currentDropDown.SelectedIndex(); uint32_t dropDownIndex = -1; bool dropDownFound = parent.Children().IndexOf(currentDropDown, dropDownIndex); @@ -312,7 +317,7 @@ 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, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox& targetApp) +void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox& targetApp) { auto onSelectionChange = [&, table, shortcutControl, colIndex, parent, targetApp](winrt::Windows::Foundation::IInspectable const& sender) { std::pair validationResult = ValidateShortcutSelection(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp); @@ -357,12 +362,12 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo }; // Rather than on every selection change (which gets triggered on searching as well) we set the handler only when the drop down is closed - dropDown.DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) { + dropDown.as().DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) { onSelectionChange(sender); }); // We check if the selection changed was triggered while the drop down was closed. This is required to handle Type key, initial loading of remaps and if the user just types in the combo box without opening it - dropDown.SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) { + dropDown.as().SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) { ComboBox currentDropDown = sender.as(); if (!currentDropDown.IsDropDownOpen()) { @@ -374,13 +379,13 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo // Function to set the selected index of the drop down void KeyDropDownControl::SetSelectedIndex(int32_t index) { - dropDown.SelectedIndex(index); + dropDown.as().SelectedIndex(index); } // Function to return the combo box element of the drop down ComboBox KeyDropDownControl::GetComboBox() { - return dropDown; + return dropDown.as(); } // Function to add a drop down to the shortcut stack panel @@ -471,6 +476,6 @@ void KeyDropDownControl::ValidateShortcutFromDropDownList(Grid table, StackPanel void KeyDropDownControl::SetDropDownError(ComboBox currentDropDown, hstring message) { currentDropDown.SelectedIndex(-1); - warningMessage.Text(message); - currentDropDown.ContextFlyout().ShowAttachedFlyout((FrameworkElement)dropDown); + warningMessage.as().Text(message); + currentDropDown.ContextFlyout().ShowAttachedFlyout((FrameworkElement)dropDown.as()); } diff --git a/src/modules/keyboardmanager/ui/KeyDropDownControl.h b/src/modules/keyboardmanager/ui/KeyDropDownControl.h index 99a180f045..e80e1e7960 100644 --- a/src/modules/keyboardmanager/ui/KeyDropDownControl.h +++ b/src/modules/keyboardmanager/ui/KeyDropDownControl.h @@ -1,20 +1,43 @@ #pragma once -#include +class KeyboardManagerState; +class Shortcut; + +namespace winrt::Windows +{ + namespace Foundation + { + struct hstring; + } + + namespace UI::Xaml::Controls + { + struct StackPanel; + struct Grid; + struct ComboBox; + struct Flyout; + struct TextBlock; + } +} + +namespace KeyboardManagerHelper +{ + enum class ErrorType; +} // Wrapper class for the key drop down menu class KeyDropDownControl { private: // Stores the drop down combo box - ComboBox dropDown; + winrt::Windows::Foundation::IInspectable dropDown; // Stores the previous layout HKL previousLayout = 0; // Stores the key code list std::vector keyCodeList; // Stores the flyout warning message - TextBlock warningMessage; + winrt::Windows::Foundation::IInspectable warningMessage; // Stores the flyout attached to the current drop down - Flyout warningFlyout; + winrt::Windows::Foundation::IInspectable warningFlyout; // Function to set properties apart from the SelectionChanged event handler void SetDefaultProperties(bool isShortcut); @@ -33,13 +56,13 @@ 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(Grid& table, StackPanel& singleKeyControl, int colIndex, std::vector>& singleKeyRemapBuffer); + void SetSelectionHandler(winrt::Windows::UI::Xaml::Controls::Grid& table, winrt::Windows::UI::Xaml::Controls::StackPanel singleKeyControl, int colIndex, std::vector>& singleKeyRemapBuffer); // Function for validating the selection of shortcuts for the drop down - std::pair ValidateShortcutSelection(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp); + 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, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp); // 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(Grid& table, StackPanel& shortcutControl, StackPanel parent, int colIndex, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox& targetApp); + 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, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp); // Function to set the selected index of the drop down void SetSelectedIndex(int32_t index); @@ -48,17 +71,17 @@ public: ComboBox GetComboBox(); // Function to add a drop down to the shortcut stack panel - static void AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox& targetApp); + 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, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp); // Function to get the list of key codes from the shortcut combo box stack panel static std::vector GetKeysFromStackPanel(StackPanel parent); // Function to check if a modifier has been repeated in the previous drop downs - static bool CheckRepeatedModifier(StackPanel parent, int selectedKeyIndex, const std::vector& keyCodeList); + static bool CheckRepeatedModifier(winrt::Windows::UI::Xaml::Controls::StackPanel parent, int selectedKeyIndex, const std::vector& keyCodeList); // Function for validating the selection of shortcuts for all the associated drop downs static void ValidateShortcutFromDropDownList(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector, std::wstring>>& shortcutRemapBuffer, std::vector>& keyDropDownControlObjects, TextBox targetApp); // Function to set the warning message - void SetDropDownError(ComboBox currentDropDown, hstring message); + void SetDropDownError(winrt::Windows::UI::Xaml::Controls::ComboBox currentDropDown, winrt::hstring message); }; diff --git a/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj b/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj index 465a09432a..5706a42229 100644 --- a/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj +++ b/src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj @@ -105,6 +105,8 @@ Use pch.h + /MP %(AdditionalOptions) + /MP %(AdditionalOptions) diff --git a/src/modules/keyboardmanager/ui/ShortcutControl.cpp b/src/modules/keyboardmanager/ui/ShortcutControl.cpp index f38de4479f..70746089ba 100644 --- a/src/modules/keyboardmanager/ui/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/ui/ShortcutControl.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "ShortcutControl.h" #include "KeyDropDownControl.h" +#include "keyboardmanager/common/KeyboardManagerState.h" //Both static members are initialized to null HWND ShortcutControl::EditShortcutsWindowHandle = nullptr; @@ -8,6 +9,32 @@ KeyboardManagerState* ShortcutControl::keyboardManagerState = nullptr; // Initialized as new vector std::vector, std::wstring>> ShortcutControl::shortcutRemapBuffer; +ShortcutControl::ShortcutControl(Grid table, const int colIndex, TextBox targetApp) +{ + shortcutDropDownStackPanel = StackPanel(); + typeShortcut = Button(); + shortcutControlLayout = StackPanel(); + + shortcutDropDownStackPanel.as().Spacing(KeyboardManagerConstants::ShortcutTableDropDownSpacing); + shortcutDropDownStackPanel.as().Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal); + + typeShortcut.as