[PreviewPane]Fix location and scaling issues with different DPI (#31802)

* [PreviewPane] Monaco Previewer: await initial position, size update + use recieved coordinates

* Fixing size and position issue for all file explorer previewers
This commit is contained in:
Laszlo Nemeth 2024-03-20 15:28:43 +01:00 committed by GitHub
parent f5797a065a
commit 58e598815c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 85 additions and 15 deletions

View File

@ -29,11 +29,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
string filePath = args[0];
int hwnd = Convert.ToInt32(args[1], 16);
Rectangle s = default(Rectangle);
int left = Convert.ToInt32(args[2], 10);
int right = Convert.ToInt32(args[3], 10);
int top = Convert.ToInt32(args[4], 10);
int bottom = Convert.ToInt32(args[5], 10);
Rectangle s = new Rectangle(left, top, right - left, bottom - top);
_previewHandlerControl = new GcodePreviewHandlerControl();
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);

View File

@ -129,6 +129,12 @@ IFACEMETHODIMP GcodePreviewHandler::SetRect(const RECT* prc)
HRESULT hr = E_INVALIDARG;
if (prc != NULL)
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0 && (prc->left != 0 || prc->top != 0 || prc->right != 0 || prc->bottom != 0))
{
// GcodePreviewHandler position first initialisation, do the first preview
m_rcParent = *prc;
DoPreview();
}
if (!m_resizeEvent)
{
Logger::error(L"Failed to create resize event for GcodePreviewHandler");
@ -153,6 +159,11 @@ IFACEMETHODIMP GcodePreviewHandler::DoPreview()
{
try
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0)
{
// Postponing Start GcodePreviewHandler.exe, position not yet initialized. preview will be done after initialisation
return S_OK;
}
Logger::info(L"Starting GcodePreviewHandler.exe");
STARTUPINFO info = { sizeof(info) };

View File

@ -29,11 +29,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
string filePath = args[0];
int hwnd = Convert.ToInt32(args[1], 16);
Rectangle s = default(Rectangle);
int left = Convert.ToInt32(args[2], 10);
int right = Convert.ToInt32(args[3], 10);
int top = Convert.ToInt32(args[4], 10);
int bottom = Convert.ToInt32(args[5], 10);
Rectangle s = new Rectangle(left, top, right - left, bottom - top);
_previewHandlerControl = new MarkdownPreviewHandlerControl();
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);

View File

@ -130,6 +130,12 @@ IFACEMETHODIMP MarkdownPreviewHandler::SetRect(const RECT* prc)
HRESULT hr = E_INVALIDARG;
if (prc != NULL)
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0 && (prc->left != 0 || prc->top != 0 || prc->right != 0 || prc->bottom != 0))
{
// MDPreviewHandler position first initialisation, do the first preview
m_rcParent = *prc;
DoPreview();
}
if (!m_resizeEvent)
{
Logger::error(L"Failed to create resize event for MDPreviewHandler");
@ -154,6 +160,11 @@ IFACEMETHODIMP MarkdownPreviewHandler::DoPreview()
{
try
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0)
{
// Postponing Start MarkdownPreviewHandler.exe, position not yet initialized. preview will be done after initialisation
return S_OK;
}
Logger::info(L"Starting MarkdownPreviewHandler.exe");
STARTUPINFO info = { sizeof(info) };

View File

@ -32,11 +32,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
string filePath = args[0];
int hwnd = Convert.ToInt32(args[1], 16);
Rectangle s = default(Rectangle);
int left = Convert.ToInt32(args[2], 10);
int right = Convert.ToInt32(args[3], 10);
int top = Convert.ToInt32(args[4], 10);
int bottom = Convert.ToInt32(args[5], 10);
Rectangle s = new Rectangle(left, top, right - left, bottom - top);
_previewHandlerControl = new MonacoPreviewHandlerControl();
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);

View File

@ -129,6 +129,12 @@ IFACEMETHODIMP MonacoPreviewHandler::SetRect(const RECT* prc)
HRESULT hr = E_INVALIDARG;
if (prc != NULL)
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0 && (prc->left != 0 || prc->top != 0 || prc->right != 0 || prc->bottom != 0))
{
// MonacoPreviewHandler position first initialisation, do the first preview
m_rcParent = *prc;
DoPreview();
}
if (!m_resizeEvent)
{
Logger::error(L"Failed to create resize event for MonacoPreviewHandler");
@ -153,8 +159,13 @@ IFACEMETHODIMP MonacoPreviewHandler::DoPreview()
{
try
{
Logger::info(L"Starting MonacoPreviewHandler.exe");
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0)
{
// Postponing Start MonacoPreviewHandler.exe, position not yet initialized. preview will be done after initialisation
return S_OK;
}
Logger::info(L"Starting MonacoPreviewHandler.exe");
STARTUPINFO info = { sizeof(info) };
std::wstring cmdLine{ L"\"" + m_filePath + L"\"" };
cmdLine += L" ";

View File

@ -28,11 +28,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
string filePath = args[0];
int hwnd = Convert.ToInt32(args[1], 16);
Rectangle s = default(Rectangle);
int left = Convert.ToInt32(args[2], 10);
int right = Convert.ToInt32(args[3], 10);
int top = Convert.ToInt32(args[4], 10);
int bottom = Convert.ToInt32(args[5], 10);
Rectangle s = new Rectangle(left, top, right - left, bottom - top);
_previewHandlerControl = new PdfPreviewHandlerControl();
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);

View File

@ -127,6 +127,12 @@ IFACEMETHODIMP PdfPreviewHandler::SetRect(const RECT* prc)
HRESULT hr = E_INVALIDARG;
if (prc != NULL)
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0 && (prc->left != 0 || prc->top != 0 || prc->right != 0 || prc->bottom != 0))
{
// PdfPreviewHandler position first initialisation, do the first preview
m_rcParent = *prc;
DoPreview();
}
if (!m_resizeEvent)
{
Logger::error(L"Failed to create resize event for PdfPreviewHandler");
@ -150,6 +156,11 @@ IFACEMETHODIMP PdfPreviewHandler::DoPreview()
{
try
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0)
{
// Postponing Start PdfPreviewHandler.exe, position not yet initialized. preview will be done after initialisation
return S_OK;
}
Logger::info(L"Starting PdfPreviewHandler.exe");
STARTUPINFO info = { sizeof(info) };

View File

@ -29,11 +29,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Qoi
string filePath = args[0];
int hwnd = Convert.ToInt32(args[1], 16);
Rectangle s = default(Rectangle);
int left = Convert.ToInt32(args[2], 10);
int right = Convert.ToInt32(args[3], 10);
int top = Convert.ToInt32(args[4], 10);
int bottom = Convert.ToInt32(args[5], 10);
Rectangle s = new Rectangle(left, top, right - left, bottom - top);
_previewHandlerControl = new QoiPreviewHandlerControl();
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);

View File

@ -129,6 +129,12 @@ IFACEMETHODIMP QoiPreviewHandler::SetRect(const RECT* prc)
HRESULT hr = E_INVALIDARG;
if (prc != NULL)
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0 && (prc->left != 0 || prc->top != 0 || prc->right != 0 || prc->bottom != 0))
{
// QoiPreviewHandler position first initialisation, do the first preview
m_rcParent = *prc;
DoPreview();
}
if (!m_resizeEvent)
{
Logger::error(L"Failed to create resize event for QoiPreviewHandler");
@ -153,6 +159,11 @@ IFACEMETHODIMP QoiPreviewHandler::DoPreview()
{
try
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0)
{
// Postponing Start QoiPreviewHandler.exe, position not yet initialized. preview will be done after initialisation
return S_OK;
}
Logger::info(L"Starting QoiPreviewHandler.exe");
STARTUPINFO info = { sizeof(info) };

View File

@ -29,11 +29,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
string filePath = args[0];
int hwnd = Convert.ToInt32(args[1], 16);
Rectangle s = default(Rectangle);
int left = Convert.ToInt32(args[2], 10);
int right = Convert.ToInt32(args[3], 10);
int top = Convert.ToInt32(args[4], 10);
int bottom = Convert.ToInt32(args[5], 10);
Rectangle s = new Rectangle(left, top, right - left, bottom - top);
_previewHandlerControl = new SvgPreviewControl();
_previewHandlerControl.SetWindow((IntPtr)hwnd, s);

View File

@ -129,6 +129,12 @@ IFACEMETHODIMP SvgPreviewHandler::SetRect(const RECT* prc)
HRESULT hr = E_INVALIDARG;
if (prc != NULL)
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0 && (prc->left != 0 || prc->top != 0 || prc->right != 0 || prc->bottom != 0))
{
// SvgPreviewHandler position first initialisation, do the first preview
m_rcParent = *prc;
DoPreview();
}
if (!m_resizeEvent)
{
Logger::error(L"Failed to create resize event for SvgPreviewHandler");
@ -152,6 +158,11 @@ IFACEMETHODIMP SvgPreviewHandler::DoPreview()
{
try
{
if (m_rcParent.left == 0 && m_rcParent.top == 0 && m_rcParent.right == 0 && m_rcParent.bottom == 0)
{
// Postponing Start SvgPreviewHandler.exe, position not yet initialized. preview will be done after initialisation
return S_OK;
}
Logger::info(L"Starting SvgPreviewHandler.exe");
STARTUPINFO info = { sizeof(info) };

View File

@ -75,7 +75,7 @@ namespace Common
/// <inheritdoc />
public void SetRect(Rectangle windowBounds)
{
this.UpdateWindowBounds(parentHwnd);
this.UpdateWindowBounds(parentHwnd, windowBounds);
}
/// <inheritdoc />
@ -88,7 +88,7 @@ namespace Common
public void SetWindow(IntPtr hwnd, Rectangle rect)
{
this.parentHwnd = hwnd;
this.UpdateWindowBounds(hwnd);
this.UpdateWindowBounds(hwnd, rect);
}
/// <inheritdoc />
@ -118,7 +118,7 @@ namespace Common
/// <summary>
/// Update the Form Control window with the passed rectangle.
/// </summary>
public void UpdateWindowBounds(IntPtr hwnd)
public void UpdateWindowBounds(IntPtr hwnd, Rectangle newBounds)
{
// We must set the WS_CHILD style to change the form to a control within the Explorer preview pane
int windowStyle = NativeMethods.GetWindowLong(Handle, gwlStyle);
@ -129,12 +129,16 @@ namespace Common
NativeMethods.SetParent(Handle, hwnd);
RECT s = default(RECT);
NativeMethods.GetClientRect(hwnd, ref s);
if (Bounds.Right != s.Right || Bounds.Bottom != s.Bottom || Bounds.Left != s.Left || Bounds.Top != s.Top)
if (newBounds.IsEmpty)
{
Bounds = s.ToRectangle();
RECT s = default(RECT);
NativeMethods.GetClientRect(hwnd, ref s);
newBounds = new Rectangle(s.Left, s.Top, s.Right - s.Left, s.Bottom - s.Top);
}
if (Bounds.Right != newBounds.Right || Bounds.Bottom != newBounds.Bottom || Bounds.Left != newBounds.Left || Bounds.Top != newBounds.Top)
{
Bounds = newBounds;
}
}
}