mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
* Update SUPPORT.md * Update runner.md * Update guidance.md * Update convert-stringtable-to-resx.ps1 * Update readme.md * Update ControlType.cs * Update README.md * Update CLSID.h * Update GenericProperty`1.cs * Update project-overview.md * Update interop.cpp * Update PreviewHandlerBase.cs * Update indexer.md * Update common.md * Update two_way_pipe_message_ipc.cpp * Update PowerToys.exe.manifest * Update HotkeySettings.cs * push * Update src/tests/win-app-driver/README.md * Update doc/devdocs/akaLinks.md * Update doc/devdocs/modules/launcher/plugins/registry.md
164 lines
5.1 KiB
C#
164 lines
5.1 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using Common.ComInterlop;
|
|
|
|
namespace Common
|
|
{
|
|
/// <summary>
|
|
/// Preview Handler base class implementing interfaces required by Preview Handler.
|
|
/// </summary>
|
|
public abstract class PreviewHandlerBase : IPreviewHandler, IOleWindow, IObjectWithSite, IPreviewHandlerVisuals
|
|
{
|
|
/// <summary>
|
|
/// An instance of Preview Control Used by the Handler.
|
|
/// </summary>
|
|
private IPreviewHandlerControl previewControl;
|
|
|
|
/// <summary>
|
|
/// Hold reference for the window handle.
|
|
/// </summary>
|
|
private IntPtr parentHwnd;
|
|
|
|
/// <summary>
|
|
/// Hold the bounds of the window.
|
|
/// </summary>
|
|
private Rectangle windowBounds;
|
|
|
|
/// <summary>
|
|
/// Holds the site pointer.
|
|
/// </summary>
|
|
private object unkSite;
|
|
|
|
/// <summary>
|
|
/// Holds reference for the IPreviewHandlerFrame.
|
|
/// </summary>
|
|
private IPreviewHandlerFrame frame;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PreviewHandlerBase"/> class.
|
|
/// </summary>
|
|
public PreviewHandlerBase()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PreviewHandlerBase"/> class.
|
|
/// </summary>
|
|
public void Initialize()
|
|
{
|
|
previewControl = CreatePreviewHandlerControl();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public abstract void DoPreview();
|
|
|
|
/// <inheritdoc />
|
|
public void SetWindow(IntPtr hwnd, ref RECT rect)
|
|
{
|
|
this.parentHwnd = hwnd;
|
|
this.windowBounds = rect.ToRectangle();
|
|
this.previewControl.SetWindow(hwnd, this.windowBounds);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void SetRect(ref RECT rect)
|
|
{
|
|
this.windowBounds = rect.ToRectangle();
|
|
this.previewControl.SetRect(this.windowBounds);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Unload()
|
|
{
|
|
this.previewControl.Unload();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void SetFocus()
|
|
{
|
|
this.previewControl.SetFocus();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void QueryFocus(out IntPtr phwnd)
|
|
{
|
|
this.previewControl.QueryFocus(out IntPtr result);
|
|
phwnd = result;
|
|
if (phwnd == IntPtr.Zero)
|
|
{
|
|
throw new Win32Exception();
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public uint TranslateAccelerator(ref MSG pmsg)
|
|
{
|
|
// Current implementation simply directs all Keystrokes to IPreviewHandlerFrame. This is the recommended approach to handle keystokes for all low-integrity preview handlers.
|
|
// Source: https://learn.microsoft.com/windows/win32/shell/building-preview-handlers#ipreviewhandlertranslateaccelerator
|
|
if (this.frame != null)
|
|
{
|
|
return this.frame.TranslateAccelerator(ref pmsg);
|
|
}
|
|
|
|
const uint S_FALSE = 1;
|
|
return S_FALSE;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void GetWindow(out IntPtr phwnd)
|
|
{
|
|
phwnd = this.previewControl.GetWindowHandle();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void ContextSensitiveHelp(bool fEnterMode)
|
|
{
|
|
// Should always return NotImplementedException. Source: https://learn.microsoft.com/windows/win32/shell/building-preview-handlers#iolewindowcontextsensitivehelp
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void SetSite(object pUnkSite)
|
|
{
|
|
// Implementation logic details: https://learn.microsoft.com/windows/win32/shell/building-preview-handlers#iobjectwithsitesetsite
|
|
this.unkSite = pUnkSite;
|
|
this.frame = this.unkSite as IPreviewHandlerFrame;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void GetSite(ref Guid riid, out object ppvSite)
|
|
{
|
|
ppvSite = this.unkSite;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void SetBackgroundColor(COLORREF color)
|
|
{
|
|
this.previewControl.SetBackgroundColor(color.Color);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void SetFont(ref LOGFONT plf)
|
|
{
|
|
this.previewControl.SetFont(Font.FromLogFont(plf));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void SetTextColor(COLORREF color)
|
|
{
|
|
this.previewControl.SetTextColor(color.Color);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Provide instance of the implementation of <see cref="IPreviewHandlerControl"/>. Should be overridden by the implementation class with a control object to be used.
|
|
/// </summary>
|
|
/// <returns>Instance of the <see cref="IPreviewHandlerControl"/>.</returns>
|
|
protected abstract IPreviewHandlerControl CreatePreviewHandlerControl();
|
|
}
|
|
}
|