using WPFluent.Controls;
namespace WPFluent.Appearance;
///
/// Represents a window that is being observed for changes in appearance.
///
internal class ObservedWindow
{
private readonly HwndSource _source;
///
/// Initializes a new instance of the class.
///
/// The handle of the window.
/// The backdrop type of the window.
/// Indicates whether to update accents.
public ObservedWindow(IntPtr handle, WindowBackdropType backdrop, bool updateAccents)
{
Handle = handle;
Backdrop = backdrop;
UpdateAccents = updateAccents;
HasHook = false;
HwndSource? windowSource = HwndSource.FromHwnd(handle);
_source =
windowSource ?? throw new InvalidOperationException("Unable to determine the window source.");
}
///
/// Adds a hook to the window.
///
/// The hook to add.
public void AddHook(HwndSourceHook hook)
{
_source.AddHook(hook);
HasHook = true;
}
///
/// Removes a hook from the window.
///
/// The hook to remove.
public void RemoveHook(HwndSourceHook hook)
{
_source.RemoveHook(hook);
HasHook = false;
}
///
/// Gets the backdrop type of the window.
///
public WindowBackdropType Backdrop { get; }
///
/// Gets the handle of the window.
///
public IntPtr Handle { get; }
///
/// Gets a value indicating whether the window has a hook.
///
public bool HasHook { get; private set; }
///
/// Gets the root visual of the window.
///
public Window? RootVisual => (Window?)_source.RootVisual;
///
/// Gets a value indicating whether to update accents.
///
public bool UpdateAccents { get; }
}