2020-03-23 10:44:02 -07:00
# pragma once
# include <keyboardmanager/common/KeyboardManagerState.h>
# include <keyboardManager/common/Helpers.h>
2020-04-08 09:11:58 -07:00
# include <keyboardmanager/common/Shortcut.h>
2020-04-18 16:12:26 -07:00
# include "KeyDropDownControl.h"
2020-03-23 10:44:02 -07:00
class ShortcutControl
{
private :
// Textblock to display the selected shortcut
TextBlock shortcutText ;
2020-04-18 16:12:26 -07:00
// Stack panel for the drop downs to display the selected shortcut
StackPanel shortcutDropDownStackPanel ;
2020-03-23 10:44:02 -07:00
// Button to type the shortcut
Button typeShortcut ;
// StackPanel to parent the above controls
StackPanel shortcutControlLayout ;
public :
// Handle to the current Edit Shortcuts Window
static HWND EditShortcutsWindowHandle ;
// Pointer to the keyboard manager state
static KeyboardManagerState * keyboardManagerState ;
2020-04-09 09:20:19 -07:00
// Stores the current list of remappings
static std : : vector < std : : vector < Shortcut > > shortcutRemapBuffer ;
2020-04-18 16:12:26 -07:00
// Vector to store dynamically allocated KeyDropDownControl objects to avoid early destruction
std : : vector < std : : unique_ptr < KeyDropDownControl > > keyDropDownControlObjects ;
2020-03-23 10:44:02 -07:00
2020-04-18 16:12:26 -07:00
ShortcutControl ( const size_t rowIndex , const size_t colIndex )
2020-03-23 10:44:02 -07:00
{
2020-04-18 16:12:26 -07:00
shortcutDropDownStackPanel . RequestedTheme ( ElementTheme : : Light ) ;
shortcutDropDownStackPanel . Spacing ( 10 ) ;
shortcutDropDownStackPanel . Orientation ( Windows : : UI : : Xaml : : Controls : : Orientation : : Horizontal ) ;
KeyDropDownControl : : AddDropDown ( shortcutDropDownStackPanel , rowIndex , colIndex , shortcutRemapBuffer , keyDropDownControlObjects ) ;
2020-03-23 10:44:02 -07:00
typeShortcut . Content ( winrt : : box_value ( winrt : : to_hstring ( " Type Shortcut " ) ) ) ;
2020-04-09 09:20:19 -07:00
typeShortcut . Click ( [ & , rowIndex , colIndex ] ( IInspectable const & sender , RoutedEventArgs const & ) {
2020-03-23 10:44:02 -07:00
keyboardManagerState - > SetUIState ( KeyboardManagerUIState : : DetectShortcutWindowActivated , EditShortcutsWindowHandle ) ;
// Using the XamlRoot of the typeShortcut to get the root of the XAML host
2020-04-09 09:20:19 -07:00
createDetectShortcutWindow ( sender , sender . as < Button > ( ) . XamlRoot ( ) , shortcutRemapBuffer , * keyboardManagerState , rowIndex , colIndex ) ;
2020-03-23 10:44:02 -07:00
} ) ;
shortcutControlLayout . Background ( Windows : : UI : : Xaml : : Media : : SolidColorBrush { Windows : : UI : : Colors : : LightGray ( ) } ) ;
shortcutControlLayout . Margin ( { 0 , 0 , 0 , 10 } ) ;
shortcutControlLayout . Spacing ( 10 ) ;
shortcutControlLayout . Children ( ) . Append ( typeShortcut ) ;
2020-04-18 16:12:26 -07:00
shortcutControlLayout . Children ( ) . Append ( shortcutDropDownStackPanel ) ;
shortcutControlLayout . UpdateLayout ( ) ;
2020-03-23 10:44:02 -07:00
}
// Function to add a new row to the shortcut table. If the originalKeys and newKeys args are provided, then the displayed shortcuts are set to those values.
2020-04-18 16:12:26 -07:00
static void AddNewShortcutControlRow ( StackPanel & parent , std : : vector < std : : vector < std : : unique_ptr < ShortcutControl > > > & keyboardRemapControlObjects , Shortcut originalKeys = Shortcut ( ) , Shortcut newKeys = Shortcut ( ) ) ;
// Function to add a shortcut to the shortcut control as combo boxes
void AddShortcutToControl ( Shortcut & shortcut , StackPanel parent , KeyboardManagerState & keyboardManagerState , const size_t rowIndex , const size_t colIndex ) ;
2020-03-23 10:44:02 -07:00
// Function to return the stack panel element of the ShortcutControl. This is the externally visible UI element which can be used to add it to other layouts
StackPanel getShortcutControl ( ) ;
// Function to create the detect shortcut UI window
2020-04-18 16:12:26 -07:00
void createDetectShortcutWindow ( IInspectable const & sender , XamlRoot xamlRoot , std : : vector < std : : vector < Shortcut > > & shortcutRemapBuffer , KeyboardManagerState & keyboardManagerState , const size_t rowIndex , const size_t colIndex ) ;
2020-03-23 10:44:02 -07:00
} ;