2020-03-27 23:38:58 +08:00
# pragma once
# include <keyboardmanager/common/KeyboardManagerState.h>
2020-04-19 07:12:26 +08:00
# include "KeyDropDownControl.h"
2020-03-27 23:38:58 +08:00
class SingleKeyRemapControl
{
private :
2020-04-19 07:12:26 +08:00
// Drop down to display the selected remap key
KeyDropDownControl singleKeyRemapDropDown ;
2020-03-27 23:38:58 +08:00
// Button to type the remap key
Button typeKey ;
// StackPanel to parent the above controls
StackPanel singleKeyRemapControlLayout ;
public :
// Handle to the current Edit Keyboard Window
static HWND EditKeyboardWindowHandle ;
// Pointer to the keyboard manager state
static KeyboardManagerState * keyboardManagerState ;
2020-04-10 00:20:19 +08:00
// Stores the current list of remappings
static std : : vector < std : : vector < DWORD > > singleKeyRemapBuffer ;
2020-03-27 23:38:58 +08:00
2020-04-27 06:09:40 +08:00
SingleKeyRemapControl ( Grid table , const int colIndex , FontIcon warning , ToolTip toolTip ) :
singleKeyRemapDropDown ( false , warning , toolTip )
2020-03-27 23:38:58 +08:00
{
2020-04-22 05:14:50 +08:00
typeKey . Content ( winrt : : box_value ( L " Type Key " ) ) ;
2020-04-24 00:14:16 +08:00
typeKey . Click ( [ & ] ( winrt : : Windows : : Foundation : : IInspectable const & sender , RoutedEventArgs const & ) {
2020-03-27 23:38:58 +08:00
keyboardManagerState - > SetUIState ( KeyboardManagerUIState : : DetectSingleKeyRemapWindowActivated , EditKeyboardWindowHandle ) ;
// Using the XamlRoot of the typeKey to get the root of the XAML host
2020-04-24 00:14:16 +08:00
createDetectKeyWindow ( sender , sender . as < Button > ( ) . XamlRoot ( ) , singleKeyRemapBuffer , * keyboardManagerState ) ;
2020-03-27 23:38:58 +08:00
} ) ;
singleKeyRemapControlLayout . Margin ( { 0 , 0 , 0 , 10 } ) ;
singleKeyRemapControlLayout . Spacing ( 10 ) ;
singleKeyRemapControlLayout . Children ( ) . Append ( typeKey ) ;
2020-04-19 07:12:26 +08:00
singleKeyRemapControlLayout . Children ( ) . Append ( singleKeyRemapDropDown . GetComboBox ( ) ) ;
2020-04-24 00:14:16 +08:00
// Set selection handler for the drop down
singleKeyRemapDropDown . SetSelectionHandler ( table , singleKeyRemapControlLayout , colIndex , singleKeyRemapBuffer ) ;
2020-04-19 07:12:26 +08:00
singleKeyRemapControlLayout . UpdateLayout ( ) ;
2020-03-27 23:38:58 +08:00
}
// 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.
2020-04-24 00:14:16 +08:00
static void AddNewControlKeyRemapRow ( Grid & parent , std : : vector < std : : vector < std : : unique_ptr < SingleKeyRemapControl > > > & keyboardRemapControlObjects , const DWORD originalKey = NULL , const DWORD newKey = NULL ) ;
2020-03-27 23:38:58 +08:00
// 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
StackPanel getSingleKeyRemapControl ( ) ;
// Function to create the detect remap keys UI window
2020-04-24 00:14:16 +08:00
void createDetectKeyWindow ( winrt : : Windows : : Foundation : : IInspectable const & sender , XamlRoot xamlRoot , std : : vector < std : : vector < DWORD > > & singleKeyRemapBuffer , KeyboardManagerState & keyboardManagerState ) ;
2020-03-27 23:38:58 +08:00
} ;