Files
ZuneShell.dll/UIX/Microsoft/Iris/ViewItems/HwndHost.cs
T

115 lines
4.1 KiB
C#
Raw Normal View History

// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.ViewItems.HwndHost
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
// Assembly location: C:\Program Files\Zune\UIX.dll
using Microsoft.Iris.Drawing;
using Microsoft.Iris.Library;
using Microsoft.Iris.Markup;
using Microsoft.Iris.OS;
using Microsoft.Iris.Render;
using Microsoft.Iris.Session;
using Microsoft.Iris.UI;
using System;
namespace Microsoft.Iris.ViewItems
{
internal class HwndHost : ContentViewItem
{
private IHwndHostWindow _window;
private Color _backgroundColor;
private long _childWindowHwnd;
private IntPtr _childHwndIntPtr;
public HwndHost()
{
2021-04-02 19:10:51 -05:00
((ITrackableUIElementEvents)this).UIChange += new EventHandler(OnUIChange);
IRenderWindow renderWindow = UISession.Default.GetRenderWindow();
2021-04-02 19:10:51 -05:00
_window = renderWindow.CreateHwndHostWindow();
_window.OnHandleChanged += new EventHandler(OnHandleChanged);
renderWindow.ForwardMessageEvent += new ForwardMessageHandler(OnForwardMessage);
_backgroundColor = Color.White;
_window.BackgroundColor = new ColorF(byte.MaxValue, byte.MaxValue, byte.MaxValue);
}
protected override void OnDispose()
{
IRenderWindow renderWindow = UISession.Default.GetRenderWindow();
if (renderWindow != null)
2021-04-02 19:10:51 -05:00
renderWindow.ForwardMessageEvent -= new ForwardMessageHandler(OnForwardMessage);
if (_window != null)
{
2021-04-02 19:10:51 -05:00
_window.OnHandleChanged -= new EventHandler(OnHandleChanged);
_window.Dispose();
_window = null;
}
2021-04-02 19:10:51 -05:00
((ITrackableUIElementEvents)this).UIChange -= new EventHandler(OnUIChange);
base.OnDispose();
}
2021-04-02 19:10:51 -05:00
public long Handle => _window.Hwnd.ToInt64();
public long ChildHandle
{
2021-04-02 19:10:51 -05:00
get => _childWindowHwnd;
set
{
2021-04-02 19:10:51 -05:00
if (value == _childWindowHwnd)
return;
2021-04-02 19:10:51 -05:00
_childWindowHwnd = value;
_childHwndIntPtr = (IntPtr)ChildHandle;
}
}
public override Color Background
{
2021-04-02 19:10:51 -05:00
get => _backgroundColor;
set
{
2021-04-02 19:10:51 -05:00
if (!(_backgroundColor != value))
return;
if (value.A != byte.MaxValue)
{
ErrorManager.ReportError("HwndHost.Background must be a solid color");
}
else
{
2021-04-02 19:10:51 -05:00
_backgroundColor = value;
_window.BackgroundColor = value.RenderConvert();
FireNotification(NotificationID.Background);
}
}
}
protected override bool HasContent() => true;
2021-04-02 19:10:51 -05:00
private void OnHandleChanged(object sender, EventArgs args) => FireNotification(NotificationID.Handle);
private unsafe void OnForwardMessage(uint message, IntPtr wParam, IntPtr lParam)
{
2021-04-02 19:10:51 -05:00
if (!(_childHwndIntPtr != IntPtr.Zero))
return;
Win32Api.MSG msg;
msg.message = message;
msg.wParam = wParam;
msg.lParam = lParam;
Win32Api.MSG* msgPtr = &msg;
2021-04-02 19:10:51 -05:00
Win32Api.SendMessage(_childHwndIntPtr, 895U, IntPtr.Zero, (IntPtr)msgPtr);
}
private void OnUIChange(object sender, EventArgs args)
{
2021-04-02 19:10:51 -05:00
if (_window == null || !IsZoned || !HasVisual)
return;
Vector3 parentOffsetPxlVector;
Vector3 scaleVector;
2021-03-31 17:20:20 -05:00
GetAccumulatedOffsetAndScale(this, null, out parentOffsetPxlVector, out scaleVector);
2021-04-02 19:10:51 -05:00
Vector2 visualSize = VisualSize;
_window.ClientPosition = new Point((int)Math.Round(parentOffsetPxlVector.X), (int)Math.Round(parentOffsetPxlVector.Y));
_window.WindowSize = new Size(Math2.RoundUp(scaleVector.X * visualSize.X), Math2.RoundUp(scaleVector.Y * visualSize.Y));
_window.Visible = FullyVisible;
}
}
}