2020-03-24 01:44:02 +08:00
|
|
|
#include "pch.h"
|
|
|
|
#include "EditShortcutsWindow.h"
|
|
|
|
#include "ShortcutControl.h"
|
2020-04-19 07:12:26 +08:00
|
|
|
#include "KeyDropDownControl.h"
|
2020-04-30 08:58:31 +08:00
|
|
|
#include "XamlBridge.h"
|
2020-05-06 03:30:50 +08:00
|
|
|
#include <keyboardmanager/common/trace.h>
|
2020-05-12 03:45:55 +08:00
|
|
|
#include <keyboardmanager/common/KeyboardManagerConstants.h>
|
|
|
|
#include <common/windows_colors.h>
|
2020-05-13 01:17:27 +08:00
|
|
|
#include <common/dpi_aware.h>
|
2020-05-12 03:45:55 +08:00
|
|
|
#include "Styles.h"
|
|
|
|
#include "Dialog.h"
|
2020-05-12 11:13:07 +08:00
|
|
|
#include <keyboardmanager/dll/resource.h>
|
2020-05-12 03:45:55 +08:00
|
|
|
|
|
|
|
using namespace winrt::Windows::Foundation;
|
2020-03-24 01:44:02 +08:00
|
|
|
|
|
|
|
LRESULT CALLBACK EditShortcutsWindowProc(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
|
|
|
|
// This Hwnd will be the window handler for the Xaml Island: A child window that contains Xaml.
|
|
|
|
HWND hWndXamlIslandEditShortcutsWindow = nullptr;
|
|
|
|
// This variable is used to check if window registration has been done to avoid repeated registration leading to an error.
|
|
|
|
bool isEditShortcutsWindowRegistrationCompleted = false;
|
2020-04-15 00:24:11 +08:00
|
|
|
// Holds the native window handle of EditShortcuts Window.
|
|
|
|
HWND hwndEditShortcutsNativeWindow = nullptr;
|
|
|
|
std::mutex editShortcutsWindowMutex;
|
2020-04-30 08:58:31 +08:00
|
|
|
// Stores a pointer to the Xaml Bridge object so that it can be accessed from the window procedure
|
|
|
|
static XamlBridge* xamlBridgePtr = nullptr;
|
2020-03-24 01:44:02 +08:00
|
|
|
|
2020-05-12 03:45:55 +08:00
|
|
|
static IAsyncAction OnClickAccept(
|
|
|
|
KeyboardManagerState& keyboardManagerState,
|
|
|
|
XamlRoot root,
|
|
|
|
std::function<void()> ApplyRemappings)
|
|
|
|
{
|
|
|
|
KeyboardManagerHelper::ErrorType isSuccess = Dialog::CheckIfRemappingsAreValid<Shortcut>(
|
|
|
|
ShortcutControl::shortcutRemapBuffer,
|
|
|
|
[](Shortcut shortcut) {
|
|
|
|
return shortcut.IsValidShortcut();
|
|
|
|
});
|
|
|
|
if (isSuccess != KeyboardManagerHelper::ErrorType::NoError)
|
|
|
|
{
|
|
|
|
if (!co_await Dialog::PartialRemappingConfirmationDialog(root))
|
|
|
|
{
|
|
|
|
co_return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplyRemappings();
|
|
|
|
}
|
|
|
|
|
2020-03-24 01:44:02 +08:00
|
|
|
// Function to create the Edit Shortcuts Window
|
|
|
|
void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState)
|
|
|
|
{
|
|
|
|
// Window Registration
|
|
|
|
const wchar_t szWindowClass[] = L"EditShortcutsWindow";
|
|
|
|
|
|
|
|
if (!isEditShortcutsWindowRegistrationCompleted)
|
|
|
|
{
|
|
|
|
WNDCLASSEX windowClass = {};
|
|
|
|
windowClass.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
windowClass.lpfnWndProc = EditShortcutsWindowProc;
|
|
|
|
windowClass.hInstance = hInst;
|
|
|
|
windowClass.lpszClassName = szWindowClass;
|
|
|
|
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
|
2020-05-12 11:13:07 +08:00
|
|
|
windowClass.hIcon = (HICON)LoadImageW(
|
|
|
|
windowClass.hInstance,
|
|
|
|
MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON),
|
|
|
|
IMAGE_ICON,
|
|
|
|
48,
|
|
|
|
48,
|
|
|
|
LR_DEFAULTCOLOR);
|
2020-03-24 01:44:02 +08:00
|
|
|
if (RegisterClassEx(&windowClass) == NULL)
|
|
|
|
{
|
|
|
|
MessageBox(NULL, L"Windows registration failed!", L"Error", NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isEditShortcutsWindowRegistrationCompleted = true;
|
|
|
|
}
|
|
|
|
|
2020-05-09 08:34:24 +08:00
|
|
|
// Find center screen coordinates
|
|
|
|
RECT desktopRect;
|
|
|
|
GetClientRect(GetDesktopWindow(), &desktopRect);
|
2020-05-13 01:17:27 +08:00
|
|
|
// Calculate DPI dependent window size
|
|
|
|
int windowWidth = KeyboardManagerConstants::DefaultEditShortcutsWindowWidth;
|
|
|
|
int windowHeight = KeyboardManagerConstants::DefaultEditShortcutsWindowHeight;
|
|
|
|
DPIAware::Convert(nullptr, windowWidth, windowHeight);
|
2020-05-09 08:34:24 +08:00
|
|
|
|
2020-03-24 01:44:02 +08:00
|
|
|
// Window Creation
|
|
|
|
HWND _hWndEditShortcutsWindow = CreateWindow(
|
|
|
|
szWindowClass,
|
2020-05-09 08:34:24 +08:00
|
|
|
L"Remap Shortcuts",
|
2020-03-24 01:44:02 +08:00
|
|
|
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
2020-05-09 08:34:24 +08:00
|
|
|
(desktopRect.right / 2) - (windowWidth / 2),
|
|
|
|
(desktopRect.bottom / 2) - (windowHeight / 2),
|
|
|
|
windowWidth,
|
|
|
|
windowHeight,
|
2020-03-24 01:44:02 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
hInst,
|
|
|
|
NULL);
|
|
|
|
if (_hWndEditShortcutsWindow == NULL)
|
|
|
|
{
|
|
|
|
MessageBox(NULL, L"Call to CreateWindow failed!", L"Error", NULL);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-09 08:34:24 +08:00
|
|
|
// Ensures the window is in foreground on first startup. If this is not done, the window appears behind because the thread is not on the foreground.
|
|
|
|
if (_hWndEditShortcutsWindow)
|
|
|
|
{
|
|
|
|
SetForegroundWindow(_hWndEditShortcutsWindow);
|
|
|
|
}
|
2020-03-24 01:44:02 +08:00
|
|
|
|
2020-04-15 00:24:11 +08:00
|
|
|
// Store the newly created Edit Shortcuts window's handle.
|
|
|
|
std::unique_lock<std::mutex> hwndLock(editShortcutsWindowMutex);
|
|
|
|
hwndEditShortcutsNativeWindow = _hWndEditShortcutsWindow;
|
|
|
|
hwndLock.unlock();
|
|
|
|
|
2020-04-30 08:58:31 +08:00
|
|
|
// Create the xaml bridge object
|
|
|
|
XamlBridge xamlBridge(_hWndEditShortcutsWindow);
|
|
|
|
// DesktopSource needs to be declared before the RelativePanel xamlContainer object to avoid errors
|
|
|
|
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource desktopSource;
|
|
|
|
// Create the desktop window xaml source object and set its content
|
|
|
|
hWndXamlIslandEditShortcutsWindow = xamlBridge.InitDesktopWindowsXamlSource(desktopSource);
|
2020-03-24 01:44:02 +08:00
|
|
|
|
2020-04-30 08:58:31 +08:00
|
|
|
// Set the pointer to the xaml bridge object
|
|
|
|
xamlBridgePtr = &xamlBridge;
|
2020-03-24 01:44:02 +08:00
|
|
|
|
|
|
|
// Header for the window
|
2020-04-24 00:14:16 +08:00
|
|
|
Windows::UI::Xaml::Controls::RelativePanel header;
|
2020-03-24 01:44:02 +08:00
|
|
|
header.Margin({ 10, 10, 10, 30 });
|
|
|
|
|
|
|
|
// Header text
|
|
|
|
TextBlock headerText;
|
2020-05-09 08:34:24 +08:00
|
|
|
headerText.Text(L"Remap Shortcuts");
|
2020-03-24 01:44:02 +08:00
|
|
|
headerText.FontSize(30);
|
2020-05-09 08:34:24 +08:00
|
|
|
headerText.Margin({ 0, 0, 0, 0 });
|
2020-04-24 00:14:16 +08:00
|
|
|
header.SetAlignLeftWithPanel(headerText, true);
|
2020-03-24 01:44:02 +08:00
|
|
|
|
|
|
|
// Cancel button
|
|
|
|
Button cancelButton;
|
2020-04-22 05:14:50 +08:00
|
|
|
cancelButton.Content(winrt::box_value(L"Cancel"));
|
2020-05-12 03:45:55 +08:00
|
|
|
cancelButton.Margin({ 10, 0, 0, 0 });
|
2020-04-20 23:22:36 +08:00
|
|
|
cancelButton.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
2020-03-24 01:44:02 +08:00
|
|
|
// Close the window since settings do not need to be saved
|
|
|
|
PostMessage(_hWndEditShortcutsWindow, WM_CLOSE, 0, 0);
|
|
|
|
});
|
|
|
|
|
2020-05-06 23:34:26 +08:00
|
|
|
// Text block for information about remap key section.
|
|
|
|
TextBlock shortcutRemapInfoHeader;
|
|
|
|
shortcutRemapInfoHeader.Text(L"Select shortcut you want to change (Original Shortcut) and the shortcut (New Shortcut) you want it to invoke.");
|
|
|
|
shortcutRemapInfoHeader.Margin({ 10, 0, 0, 10 });
|
|
|
|
shortcutRemapInfoHeader.FontWeight(Text::FontWeights::SemiBold());
|
2020-05-09 08:34:24 +08:00
|
|
|
shortcutRemapInfoHeader.TextWrapping(TextWrapping::Wrap);
|
2020-05-06 23:34:26 +08:00
|
|
|
|
|
|
|
TextBlock shortcutRemapInfoExample;
|
|
|
|
shortcutRemapInfoExample.Text(L"For example, if you want Ctrl+C to paste, Ctrl+C is the Original Shortcut and Ctrl+V is the New Shortcut.");
|
|
|
|
shortcutRemapInfoExample.Margin({ 10, 0, 0, 20 });
|
|
|
|
shortcutRemapInfoExample.FontStyle(Text::FontStyle::Italic);
|
2020-05-09 08:34:24 +08:00
|
|
|
shortcutRemapInfoExample.TextWrapping(TextWrapping::Wrap);
|
2020-05-06 23:34:26 +08:00
|
|
|
|
2020-03-24 01:44:02 +08:00
|
|
|
// Table to display the shortcuts
|
2020-04-24 00:14:16 +08:00
|
|
|
Windows::UI::Xaml::Controls::Grid shortcutTable;
|
2020-05-09 08:34:24 +08:00
|
|
|
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 removeColumn;
|
|
|
|
removeColumn.MinWidth(KeyboardManagerConstants::TableRemoveColWidth);
|
2020-03-24 01:44:02 +08:00
|
|
|
shortcutTable.Margin({ 10, 10, 10, 20 });
|
2020-04-24 00:14:16 +08:00
|
|
|
shortcutTable.HorizontalAlignment(HorizontalAlignment::Stretch);
|
2020-05-09 08:34:24 +08:00
|
|
|
shortcutTable.ColumnDefinitions().Append(originalColumn);
|
|
|
|
shortcutTable.ColumnDefinitions().Append(arrowColumn);
|
|
|
|
shortcutTable.ColumnDefinitions().Append(newColumn);
|
|
|
|
shortcutTable.ColumnDefinitions().Append(removeColumn);
|
2020-04-24 00:14:16 +08:00
|
|
|
shortcutTable.RowDefinitions().Append(RowDefinition());
|
2020-03-24 01:44:02 +08:00
|
|
|
|
|
|
|
// First header textblock in the header row of the shortcut table
|
|
|
|
TextBlock originalShortcutHeader;
|
2020-04-22 05:14:50 +08:00
|
|
|
originalShortcutHeader.Text(L"Original Shortcut:");
|
2020-03-24 01:44:02 +08:00
|
|
|
originalShortcutHeader.FontWeight(Text::FontWeights::Bold());
|
|
|
|
originalShortcutHeader.Margin({ 0, 0, 0, 10 });
|
|
|
|
|
2020-04-04 01:57:46 +08:00
|
|
|
// Second header textblock in the header row of the shortcut table
|
2020-03-24 01:44:02 +08:00
|
|
|
TextBlock newShortcutHeader;
|
2020-04-22 05:14:50 +08:00
|
|
|
newShortcutHeader.Text(L"New Shortcut:");
|
2020-03-24 01:44:02 +08:00
|
|
|
newShortcutHeader.FontWeight(Text::FontWeights::Bold());
|
|
|
|
newShortcutHeader.Margin({ 0, 0, 0, 10 });
|
|
|
|
|
2020-05-09 08:34:24 +08:00
|
|
|
shortcutTable.SetColumn(originalShortcutHeader, KeyboardManagerConstants::ShortcutTableOriginalColIndex);
|
2020-04-27 06:09:40 +08:00
|
|
|
shortcutTable.SetRow(originalShortcutHeader, 0);
|
2020-05-09 08:34:24 +08:00
|
|
|
shortcutTable.SetColumn(newShortcutHeader, KeyboardManagerConstants::ShortcutTableNewColIndex);
|
2020-04-24 00:14:16 +08:00
|
|
|
shortcutTable.SetRow(newShortcutHeader, 0);
|
|
|
|
|
|
|
|
shortcutTable.Children().Append(originalShortcutHeader);
|
|
|
|
shortcutTable.Children().Append(newShortcutHeader);
|
2020-03-24 01:44:02 +08:00
|
|
|
|
2020-04-10 00:20:19 +08:00
|
|
|
// Store handle of edit shortcuts window
|
|
|
|
ShortcutControl::EditShortcutsWindowHandle = _hWndEditShortcutsWindow;
|
|
|
|
// Store keyboard manager state
|
|
|
|
ShortcutControl::keyboardManagerState = &keyboardManagerState;
|
2020-04-19 07:12:26 +08:00
|
|
|
KeyDropDownControl::keyboardManagerState = &keyboardManagerState;
|
2020-04-10 00:20:19 +08:00
|
|
|
// Clear the shortcut remap buffer
|
|
|
|
ShortcutControl::shortcutRemapBuffer.clear();
|
2020-04-19 07:12:26 +08:00
|
|
|
// Vector to store dynamically allocated control objects to avoid early destruction
|
|
|
|
std::vector<std::vector<std::unique_ptr<ShortcutControl>>> keyboardRemapControlObjects;
|
2020-04-10 00:20:19 +08:00
|
|
|
|
2020-05-05 06:49:37 +08:00
|
|
|
// Set keyboard manager UI state so that shortcut remaps are not applied while on this window
|
|
|
|
keyboardManagerState.SetUIState(KeyboardManagerUIState::EditShortcutsWindowActivated, _hWndEditShortcutsWindow);
|
|
|
|
|
2020-04-10 00:20:19 +08:00
|
|
|
// Load existing shortcuts into UI
|
|
|
|
std::unique_lock<std::mutex> lock(keyboardManagerState.osLevelShortcutReMap_mutex);
|
|
|
|
for (const auto& it : keyboardManagerState.osLevelShortcutReMap)
|
|
|
|
{
|
2020-04-19 07:12:26 +08:00
|
|
|
ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects, it.first, it.second.targetShortcut);
|
2020-04-10 00:20:19 +08:00
|
|
|
}
|
|
|
|
lock.unlock();
|
|
|
|
|
2020-03-24 01:44:02 +08:00
|
|
|
// Apply button
|
|
|
|
Button applyButton;
|
2020-05-12 03:45:55 +08:00
|
|
|
applyButton.Content(winrt::box_value(L"OK"));
|
|
|
|
applyButton.Style(AccentButtonStyle());
|
|
|
|
applyButton.MinWidth(KeyboardManagerConstants::HeaderButtonWidth);
|
|
|
|
cancelButton.MinWidth(KeyboardManagerConstants::HeaderButtonWidth);
|
|
|
|
header.SetAlignRightWithPanel(cancelButton, true);
|
|
|
|
header.SetLeftOf(applyButton, cancelButton);
|
|
|
|
|
|
|
|
auto ApplyRemappings = [&keyboardManagerState, _hWndEditShortcutsWindow]() {
|
2020-04-27 06:09:40 +08:00
|
|
|
KeyboardManagerHelper::ErrorType isSuccess = KeyboardManagerHelper::ErrorType::NoError;
|
2020-03-24 01:44:02 +08:00
|
|
|
// Clear existing shortcuts
|
|
|
|
keyboardManagerState.ClearOSLevelShortcuts();
|
2020-05-06 03:30:50 +08:00
|
|
|
DWORD successfulRemapCount = 0;
|
2020-03-24 01:44:02 +08:00
|
|
|
// Save the shortcuts that are valid and report if any of them were invalid
|
2020-04-10 00:20:19 +08:00
|
|
|
for (int i = 0; i < ShortcutControl::shortcutRemapBuffer.size(); i++)
|
2020-03-24 01:44:02 +08:00
|
|
|
{
|
2020-04-10 00:20:19 +08:00
|
|
|
Shortcut originalShortcut = ShortcutControl::shortcutRemapBuffer[i][0];
|
|
|
|
Shortcut newShortcut = ShortcutControl::shortcutRemapBuffer[i][1];
|
2020-03-24 01:44:02 +08:00
|
|
|
|
2020-04-19 07:12:26 +08:00
|
|
|
if (originalShortcut.IsValidShortcut() && newShortcut.IsValidShortcut())
|
2020-04-10 00:20:19 +08:00
|
|
|
{
|
|
|
|
bool result = keyboardManagerState.AddOSLevelShortcut(originalShortcut, newShortcut);
|
|
|
|
if (!result)
|
2020-03-24 01:44:02 +08:00
|
|
|
{
|
2020-04-27 06:09:40 +08:00
|
|
|
isSuccess = KeyboardManagerHelper::ErrorType::RemapUnsuccessful;
|
|
|
|
// Tooltip is already shown for this row
|
2020-03-24 01:44:02 +08:00
|
|
|
}
|
2020-05-06 03:30:50 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
successfulRemapCount += 1;
|
|
|
|
}
|
2020-03-24 01:44:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-27 06:09:40 +08:00
|
|
|
isSuccess = KeyboardManagerHelper::ErrorType::RemapUnsuccessful;
|
2020-03-24 01:44:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 03:45:55 +08:00
|
|
|
Trace::OSLevelShortcutRemapCount(successfulRemapCount);
|
2020-04-20 23:22:36 +08:00
|
|
|
// Save the updated key remaps to file.
|
2020-04-27 06:09:40 +08:00
|
|
|
bool saveResult = keyboardManagerState.SaveConfigToFile();
|
|
|
|
if (!saveResult)
|
2020-04-20 23:22:36 +08:00
|
|
|
{
|
2020-04-27 06:09:40 +08:00
|
|
|
isSuccess = KeyboardManagerHelper::ErrorType::SaveFailed;
|
2020-04-20 23:22:36 +08:00
|
|
|
}
|
2020-05-12 03:45:55 +08:00
|
|
|
|
|
|
|
PostMessage(_hWndEditShortcutsWindow, WM_CLOSE, 0, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
applyButton.Click([&keyboardManagerState, applyButton, ApplyRemappings](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
|
|
|
OnClickAccept(keyboardManagerState, applyButton.XamlRoot(), ApplyRemappings);
|
2020-03-24 01:44:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
header.Children().Append(headerText);
|
|
|
|
header.Children().Append(cancelButton);
|
|
|
|
header.Children().Append(applyButton);
|
|
|
|
|
|
|
|
// Add shortcut button
|
|
|
|
Windows::UI::Xaml::Controls::Button addShortcut;
|
|
|
|
FontIcon plusSymbol;
|
|
|
|
plusSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets"));
|
|
|
|
plusSymbol.Glyph(L"\xE109");
|
|
|
|
addShortcut.Content(plusSymbol);
|
2020-04-27 12:57:51 +08:00
|
|
|
addShortcut.Margin({ 10, 0, 0, 25 });
|
2020-04-20 23:22:36 +08:00
|
|
|
addShortcut.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
2020-04-19 07:12:26 +08:00
|
|
|
ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects);
|
2020-03-24 01:44:02 +08:00
|
|
|
});
|
|
|
|
|
2020-04-27 12:57:51 +08:00
|
|
|
StackPanel mappingsPanel;
|
2020-05-06 23:34:26 +08:00
|
|
|
mappingsPanel.Children().Append(shortcutRemapInfoHeader);
|
|
|
|
mappingsPanel.Children().Append(shortcutRemapInfoExample);
|
2020-04-27 12:57:51 +08:00
|
|
|
mappingsPanel.Children().Append(shortcutTable);
|
|
|
|
mappingsPanel.Children().Append(addShortcut);
|
|
|
|
|
|
|
|
ScrollViewer scrollViewer;
|
|
|
|
scrollViewer.Content(mappingsPanel);
|
|
|
|
|
|
|
|
RelativePanel xamlContainer;
|
|
|
|
xamlContainer.SetBelow(scrollViewer, header);
|
|
|
|
xamlContainer.SetAlignLeftWithPanel(header, true);
|
|
|
|
xamlContainer.SetAlignRightWithPanel(header, true);
|
|
|
|
xamlContainer.SetAlignLeftWithPanel(scrollViewer, true);
|
|
|
|
xamlContainer.SetAlignRightWithPanel(scrollViewer, true);
|
2020-03-24 01:44:02 +08:00
|
|
|
xamlContainer.Children().Append(header);
|
2020-04-27 12:57:51 +08:00
|
|
|
xamlContainer.Children().Append(scrollViewer);
|
2020-03-24 01:44:02 +08:00
|
|
|
xamlContainer.UpdateLayout();
|
2020-04-30 08:58:31 +08:00
|
|
|
|
2020-03-24 01:44:02 +08:00
|
|
|
desktopSource.Content(xamlContainer);
|
|
|
|
|
|
|
|
////End XAML Island section
|
|
|
|
if (_hWndEditShortcutsWindow)
|
|
|
|
{
|
|
|
|
ShowWindow(_hWndEditShortcutsWindow, SW_SHOW);
|
|
|
|
UpdateWindow(_hWndEditShortcutsWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message loop:
|
2020-04-30 08:58:31 +08:00
|
|
|
xamlBridge.MessageLoop();
|
2020-04-15 00:24:11 +08:00
|
|
|
|
2020-04-30 08:58:31 +08:00
|
|
|
// Reset pointers to nullptr
|
|
|
|
xamlBridgePtr = nullptr;
|
2020-04-15 00:24:11 +08:00
|
|
|
hWndXamlIslandEditShortcutsWindow = nullptr;
|
|
|
|
hwndLock.lock();
|
|
|
|
hwndEditShortcutsNativeWindow = nullptr;
|
2020-05-05 06:49:37 +08:00
|
|
|
keyboardManagerState.ResetUIState();
|
2020-04-30 08:58:31 +08:00
|
|
|
|
|
|
|
// Cannot be done in WM_DESTROY because that causes crashes due to fatal app exit
|
|
|
|
xamlBridge.ClearXamlIslands();
|
2020-03-24 01:44:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK EditShortcutsWindowProc(HWND hWnd, UINT messageCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
RECT rcClient;
|
|
|
|
switch (messageCode)
|
|
|
|
{
|
2020-04-24 00:14:16 +08:00
|
|
|
// Resize the XAML window whenever the parent window is painted or resized
|
2020-03-24 01:44:02 +08:00
|
|
|
case WM_PAINT:
|
2020-04-24 00:14:16 +08:00
|
|
|
case WM_SIZE:
|
2020-03-24 01:44:02 +08:00
|
|
|
GetClientRect(hWnd, &rcClient);
|
|
|
|
SetWindowPos(hWndXamlIslandEditShortcutsWindow, 0, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom, SWP_SHOWWINDOW);
|
|
|
|
break;
|
|
|
|
default:
|
2020-04-30 08:58:31 +08:00
|
|
|
// If the Xaml Bridge object exists, then use it's message handler to handle keyboard focus operations
|
|
|
|
if (xamlBridgePtr != nullptr)
|
|
|
|
{
|
|
|
|
return xamlBridgePtr->MessageHandler(messageCode, wParam, lParam);
|
|
|
|
}
|
2020-05-02 08:34:42 +08:00
|
|
|
else if (messageCode == WM_NCDESTROY)
|
2020-04-30 08:58:31 +08:00
|
|
|
{
|
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-24 01:44:02 +08:00
|
|
|
return DefWindowProc(hWnd, messageCode, wParam, lParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-15 00:24:11 +08:00
|
|
|
|
2020-04-30 08:58:31 +08:00
|
|
|
// Function to check if there is already a window active if yes bring to foreground
|
2020-04-20 23:59:35 +08:00
|
|
|
bool CheckEditShortcutsWindowActive()
|
2020-04-15 00:24:11 +08:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
std::unique_lock<std::mutex> hwndLock(editShortcutsWindowMutex);
|
|
|
|
if (hwndEditShortcutsNativeWindow != nullptr)
|
|
|
|
{
|
|
|
|
// Check if the window is minimized if yes then restore the window.
|
|
|
|
if (IsIconic(hwndEditShortcutsNativeWindow))
|
|
|
|
{
|
|
|
|
ShowWindow(hwndEditShortcutsNativeWindow, SW_RESTORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is an already existing window no need to create a new open bring it on foreground.
|
|
|
|
SetForegroundWindow(hwndEditShortcutsNativeWindow);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|