2020-04-18 16:12:26 -07:00
# pragma once
2020-07-23 16:43:49 -07:00
# include <keyboardmanager/common/Shortcut.h>
# include <variant>
2020-07-13 11:49:09 -07:00
class KeyboardManagerState ;
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 ;
}
2020-04-18 16:12:26 -07:00
// Wrapper class for the key drop down menu
class KeyDropDownControl
{
private :
// Stores the drop down combo box
2020-07-13 11:49:09 -07:00
winrt : : Windows : : Foundation : : IInspectable dropDown ;
2020-04-18 16:12:26 -07:00
// Stores the previous layout
HKL previousLayout = 0 ;
// Stores the key code list
std : : vector < DWORD > keyCodeList ;
2020-05-11 10:10:36 -07:00
// Stores the flyout warning message
2020-07-13 11:49:09 -07:00
winrt : : Windows : : Foundation : : IInspectable warningMessage ;
2020-05-11 10:10:36 -07:00
// Stores the flyout attached to the current drop down
2020-07-13 11:49:09 -07:00
winrt : : Windows : : Foundation : : IInspectable warningFlyout ;
2020-04-18 16:12:26 -07:00
// Function to set properties apart from the SelectionChanged event handler
void SetDefaultProperties ( bool isShortcut ) ;
// Function to check if the layout has changed and accordingly update the drop down list
void CheckAndUpdateKeyboardLayout ( ComboBox currentDropDown , bool isShortcut ) ;
public :
// Pointer to the keyboard manager state
static KeyboardManagerState * keyboardManagerState ;
2020-05-11 10:10:36 -07:00
// Constructor - the last default parameter should be passed as false only if it originates from Type shortcut or when an old shortcut is reloaded
KeyDropDownControl ( bool isShortcut )
2020-04-18 16:12:26 -07:00
{
2020-04-23 09:14:16 -07:00
SetDefaultProperties ( isShortcut ) ;
2020-04-18 16:12:26 -07:00
}
2020-04-23 09:14:16 -07:00
// 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
2020-07-23 16:43:49 -07:00
void SetSelectionHandler ( winrt : : Windows : : UI : : Xaml : : Controls : : Grid & table , winrt : : Windows : : UI : : Xaml : : Controls : : StackPanel singleKeyControl , int colIndex , std : : vector < std : : pair < std : : vector < std : : variant < DWORD , Shortcut > > , std : : wstring > > & singleKeyRemapBuffer ) ;
2020-04-18 16:12:26 -07:00
2020-06-10 08:25:41 -07:00
// Function for validating the selection of shortcuts for the drop down
2020-07-23 16:43:49 -07:00
std : : pair < KeyboardManagerHelper : : ErrorType , int > 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 : : pair < std : : vector < std : : variant < DWORD , Shortcut > > , std : : wstring > > & shortcutRemapBuffer , std : : vector < std : : unique_ptr < KeyDropDownControl > > & keyDropDownControlObjects , winrt : : Windows : : UI : : Xaml : : Controls : : TextBox targetApp , bool isHybridControl , bool isSingleKeyWindow ) ;
2020-06-10 08:25:41 -07:00
2020-04-23 09:14:16 -07:00
// 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
2020-07-23 16:43:49 -07:00
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 : : pair < std : : vector < std : : variant < DWORD , Shortcut > > , std : : wstring > > & shortcutRemapBuffer , std : : vector < std : : unique_ptr < KeyDropDownControl > > & keyDropDownControlObjects , winrt : : Windows : : UI : : Xaml : : Controls : : TextBox & targetApp , bool isHybridControl , bool isSingleKeyWindow ) ;
2020-04-18 16:12:26 -07:00
// Function to set the selected index of the drop down
void SetSelectedIndex ( int32_t index ) ;
// Function to return the combo box element of the drop down
ComboBox GetComboBox ( ) ;
// Function to add a drop down to the shortcut stack panel
2020-07-23 16:43:49 -07:00
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 : : pair < std : : vector < std : : variant < DWORD , Shortcut > > , std : : wstring > > & shortcutRemapBuffer , std : : vector < std : : unique_ptr < KeyDropDownControl > > & keyDropDownControlObjects , winrt : : Windows : : UI : : Xaml : : Controls : : TextBox targetApp , bool isHybridControl , bool isSingleKeyWindow ) ;
2020-04-18 16:12:26 -07:00
// Function to get the list of key codes from the shortcut combo box stack panel
2020-06-10 08:25:41 -07:00
static std : : vector < DWORD > GetKeysFromStackPanel ( StackPanel parent ) ;
2020-04-18 16:12:26 -07:00
// Function to check if a modifier has been repeated in the previous drop downs
2020-07-13 11:49:09 -07:00
static bool CheckRepeatedModifier ( winrt : : Windows : : UI : : Xaml : : Controls : : StackPanel parent , int selectedKeyIndex , const std : : vector < DWORD > & keyCodeList ) ;
2020-04-18 16:12:26 -07:00
2020-07-08 16:24:30 -07:00
// Function for validating the selection of shortcuts for all the associated drop downs
2020-07-23 16:43:49 -07:00
static void ValidateShortcutFromDropDownList ( Grid table , StackPanel shortcutControl , StackPanel parent , int colIndex , std : : vector < std : : pair < std : : vector < std : : variant < DWORD , Shortcut > > , std : : wstring > > & shortcutRemapBuffer , std : : vector < std : : unique_ptr < KeyDropDownControl > > & keyDropDownControlObjects , TextBox targetApp , bool isHybridControl , bool isSingleKeyWindow ) ;
2020-07-08 16:24:30 -07:00
2020-04-26 15:09:40 -07:00
// Function to set the warning message
2020-07-13 11:49:09 -07:00
void SetDropDownError ( winrt : : Windows : : UI : : Xaml : : Controls : : ComboBox currentDropDown , winrt : : hstring message ) ;
2020-07-23 16:43:49 -07:00
// 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 < std : : unique_ptr < KeyDropDownControl > > & keyDropDownControlObjects , std : : vector < std : : pair < std : : vector < std : : variant < DWORD , Shortcut > > , std : : wstring > > & remapBuffer , StackPanel controlLayout , TextBox targetApp , bool isHybridControl , bool isSingleKeyWindow ) ;
2020-04-18 16:12:26 -07:00
} ;