2020-04-30 08:58:31 +08:00
|
|
|
#pragma once
|
|
|
|
#include <unknwn.h> // To enable support for non-WinRT interfaces, unknwn.h must be included before any C++/WinRT headers.
|
|
|
|
#include <winrt/Windows.System.h>
|
|
|
|
#include <winrt/Windows.Foundation.h>
|
|
|
|
#include <winrt/Windows.Foundation.Collections.h>
|
|
|
|
#include <winrt/Windows.UI.Xaml.Hosting.h>
|
|
|
|
#include <winrt/Windows.UI.Xaml.Markup.h>
|
|
|
|
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
|
|
|
|
#include <windowsx.h>
|
|
|
|
|
|
|
|
// This class is used for handling XAML Island operations
|
|
|
|
class XamlBridge
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Function to run the message loop for the xaml island window
|
|
|
|
int MessageLoop();
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
XamlBridge(HWND parent) :
|
2020-05-05 02:36:57 +08:00
|
|
|
parentWindow(parent), lastFocusRequestId(winrt::guid()), winxamlmanager(nullptr)
|
2020-04-30 08:58:31 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to initialise the xaml source object
|
|
|
|
HWND InitDesktopWindowsXamlSource(winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource);
|
|
|
|
|
|
|
|
// Function to close and delete all the xaml source objects
|
|
|
|
void ClearXamlIslands();
|
|
|
|
|
|
|
|
// Message Handler function for Xaml Island windows
|
|
|
|
LRESULT MessageHandler(UINT const message, WPARAM const wParam, LPARAM const lParam) noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Stores the last window handle in focus
|
|
|
|
HWND m_hwndLastFocus = nullptr;
|
|
|
|
|
|
|
|
// Stores the handle of the parent native window
|
|
|
|
HWND parentWindow = nullptr;
|
|
|
|
|
2020-05-05 02:36:57 +08:00
|
|
|
// Window xaml manager for UI thread.
|
|
|
|
WindowsXamlManager winxamlmanager;
|
|
|
|
|
2020-04-30 08:58:31 +08:00
|
|
|
// Stores the GUID of the last focus request
|
|
|
|
winrt::guid lastFocusRequestId;
|
|
|
|
|
|
|
|
// Function to return the xaml island currently in focus
|
|
|
|
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource GetFocusedIsland();
|
|
|
|
|
|
|
|
// Function to pre process the message on the xaml source object
|
|
|
|
bool FilterMessage(const MSG* msg);
|
|
|
|
|
|
|
|
// Event triggered when focus is requested
|
|
|
|
void OnTakeFocusRequested(winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource const& sender, winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSourceTakeFocusRequestedEventArgs const& args);
|
|
|
|
|
|
|
|
// Function to return the next xaml island in focus
|
|
|
|
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource GetNextFocusedIsland(MSG* msg);
|
|
|
|
|
|
|
|
// Function to handle focus navigation
|
|
|
|
bool NavigateFocus(MSG* msg);
|
|
|
|
|
|
|
|
// Stores the focus event objects
|
|
|
|
std::vector<winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource::TakeFocusRequested_revoker> m_takeFocusEventRevokers;
|
|
|
|
|
|
|
|
// Stores the xaml source objects
|
|
|
|
std::vector<winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource> m_xamlSources;
|
|
|
|
|
|
|
|
// Function invoked when the window is destroyed
|
|
|
|
void OnDestroy(HWND);
|
|
|
|
|
|
|
|
// Function invoked when the window is activated
|
|
|
|
void OnActivate(HWND, UINT state, HWND hwndActDeact, BOOL fMinimized);
|
|
|
|
|
|
|
|
// Function invoked when the window is set to focus
|
|
|
|
void OnSetFocus(HWND, HWND hwndOldFocus);
|
|
|
|
};
|