2021-03-31 16:42:58 -05:00
|
|
|
// 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);
|
2021-03-31 16:42:58 -05:00
|
|
|
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);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-03-31 16:42:58 -05:00
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
_window.OnHandleChanged -= new EventHandler(OnHandleChanged);
|
|
|
|
|
_window.Dispose();
|
|
|
|
|
_window = null;
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
2021-04-02 19:10:51 -05:00
|
|
|
((ITrackableUIElementEvents)this).UIChange -= new EventHandler(OnUIChange);
|
2021-03-31 16:42:58 -05:00
|
|
|
base.OnDispose();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 19:10:51 -05:00
|
|
|
public long Handle => _window.Hwnd.ToInt64();
|
2021-03-31 16:42:58 -05:00
|
|
|
|
|
|
|
|
public long ChildHandle
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
get => _childWindowHwnd;
|
2021-03-31 16:42:58 -05:00
|
|
|
set
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (value == _childWindowHwnd)
|
2021-03-31 16:42:58 -05:00
|
|
|
return;
|
2021-04-02 19:10:51 -05:00
|
|
|
_childWindowHwnd = value;
|
|
|
|
|
_childHwndIntPtr = (IntPtr)ChildHandle;
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Color Background
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
get => _backgroundColor;
|
2021-03-31 16:42:58 -05:00
|
|
|
set
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (!(_backgroundColor != value))
|
2021-03-31 16:42:58 -05:00
|
|
|
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);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool HasContent() => true;
|
|
|
|
|
|
2021-04-02 19:10:51 -05:00
|
|
|
private void OnHandleChanged(object sender, EventArgs args) => FireNotification(NotificationID.Handle);
|
2021-03-31 16:42:58 -05:00
|
|
|
|
|
|
|
|
private unsafe void OnForwardMessage(uint message, IntPtr wParam, IntPtr lParam)
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (!(_childHwndIntPtr != IntPtr.Zero))
|
2021-03-31 16:42:58 -05:00
|
|
|
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);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnUIChange(object sender, EventArgs args)
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (_window == null || !IsZoned || !HasVisual)
|
2021-03-31 16:42:58 -05:00
|
|
|
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;
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|