PreviewerWindowImpl.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Platform;
  4. using Avalonia.Controls.Remote.Server;
  5. using Avalonia.Input;
  6. using Avalonia.Platform;
  7. using Avalonia.Platform.Storage;
  8. using Avalonia.Remote.Protocol;
  9. using Avalonia.Remote.Protocol.Viewport;
  10. using Avalonia.Threading;
  11. namespace Avalonia.DesignerSupport.Remote
  12. {
  13. class PreviewerWindowImpl : RemoteServerTopLevelImpl, IWindowImpl
  14. {
  15. private readonly IAvaloniaRemoteTransportConnection _transport;
  16. public PreviewerWindowImpl(IAvaloniaRemoteTransportConnection transport) : base(transport)
  17. {
  18. _transport = transport;
  19. ClientSize = new Size(1, 1);
  20. }
  21. public void Show(bool activate, bool isDialog)
  22. {
  23. }
  24. public void Hide()
  25. {
  26. }
  27. public void BeginMoveDrag(PointerPressedEventArgs e)
  28. {
  29. }
  30. public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
  31. {
  32. }
  33. public double DesktopScaling => 1.0;
  34. public PixelPoint Position { get; set; }
  35. public Action<PixelPoint> PositionChanged { get; set; }
  36. public Action Deactivated { get; set; }
  37. public Action Activated { get; set; }
  38. public Func<WindowCloseReason, bool> Closing { get; set; }
  39. public IPlatformHandle Handle { get; }
  40. public WindowState WindowState { get; set; }
  41. public Action<WindowState> WindowStateChanged { get; set; }
  42. public Size MaxAutoSizeHint { get; } = new Size(4096, 4096);
  43. protected override void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj)
  44. {
  45. // In previewer mode we completely ignore client-side viewport size
  46. if (obj is ClientViewportAllocatedMessage alloc)
  47. {
  48. Dispatcher.UIThread.Post(() =>
  49. {
  50. RenderScaling = alloc.DpiX / 96.0;
  51. RenderAndSendFrameIfNeeded();
  52. });
  53. return;
  54. }
  55. base.OnMessage(transport, obj);
  56. }
  57. public void Resize(Size clientSize, WindowResizeReason reason)
  58. {
  59. _transport.Send(new RequestViewportResizeMessage
  60. {
  61. Width = Math.Ceiling(clientSize.Width * RenderScaling),
  62. Height = Math.Ceiling(clientSize.Height * RenderScaling)
  63. });
  64. ClientSize = clientSize;
  65. RenderAndSendFrameIfNeeded();
  66. }
  67. public void Move(PixelPoint point)
  68. {
  69. }
  70. public void SetMinMaxSize(Size minSize, Size maxSize)
  71. {
  72. }
  73. public Action GotInputWhenDisabled { get; set; }
  74. public Action<bool> ExtendClientAreaToDecorationsChanged { get; set; }
  75. public Thickness ExtendedMargins { get; } = new Thickness();
  76. public bool IsClientAreaExtendedToDecorations { get; }
  77. public Thickness OffScreenMargin { get; } = new Thickness();
  78. public bool NeedsManagedDecorations => false;
  79. public override object TryGetFeature(Type featureType)
  80. {
  81. if (featureType == typeof(IStorageProvider))
  82. {
  83. return new NoopStorageProvider();
  84. }
  85. if (featureType == typeof(IScreenImpl))
  86. {
  87. return new ScreenStub();
  88. }
  89. return base.TryGetFeature(featureType);
  90. }
  91. public void Activate()
  92. {
  93. }
  94. public void SetTitle(string title)
  95. {
  96. }
  97. public void SetSystemDecorations(SystemDecorations enabled)
  98. {
  99. }
  100. public void SetIcon(IWindowIconImpl icon)
  101. {
  102. }
  103. public void ShowTaskbarIcon(bool value)
  104. {
  105. }
  106. public void CanResize(bool value)
  107. {
  108. }
  109. public void SetTopmost(bool value)
  110. {
  111. }
  112. public void SetParent(IWindowImpl parent)
  113. {
  114. }
  115. public void SetEnabled(bool enable)
  116. {
  117. }
  118. public void SetExtendClientAreaToDecorationsHint(bool extendIntoClientAreaHint)
  119. {
  120. }
  121. public void SetExtendClientAreaChromeHints(ExtendClientAreaChromeHints hints)
  122. {
  123. }
  124. public void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight)
  125. {
  126. }
  127. public void GetWindowsZOrder(Span<Window> windows, Span<long> zOrder) => throw new NotSupportedException();
  128. }
  129. }