Stubs.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reactive.Disposables;
  5. using System.Threading.Tasks;
  6. using Avalonia.Controls;
  7. using Avalonia.Controls.Platform;
  8. using Avalonia.Controls.Primitives.PopupPositioning;
  9. using Avalonia.Input;
  10. using Avalonia.Input.Platform;
  11. using Avalonia.Input.Raw;
  12. using Avalonia.Platform;
  13. using Avalonia.Rendering;
  14. namespace Avalonia.DesignerSupport.Remote
  15. {
  16. class WindowStub : IWindowImpl, IPopupImpl
  17. {
  18. public Action Deactivated { get; set; }
  19. public Action Activated { get; set; }
  20. public IPlatformHandle Handle { get; }
  21. public Size MaxClientSize { get; }
  22. public Size ClientSize { get; }
  23. public double Scaling { get; } = 1.0;
  24. public IEnumerable<object> Surfaces { get; }
  25. public Action<RawInputEventArgs> Input { get; set; }
  26. public Action<Rect> Paint { get; set; }
  27. public Action<Size> Resized { get; set; }
  28. public Action<double> ScalingChanged { get; set; }
  29. public Func<bool> Closing { get; set; }
  30. public Action Closed { get; set; }
  31. public IMouseDevice MouseDevice { get; } = new MouseDevice();
  32. public IPopupImpl CreatePopup() => new WindowStub(this);
  33. public PixelPoint Position { get; set; }
  34. public Action<PixelPoint> PositionChanged { get; set; }
  35. public WindowState WindowState { get; set; }
  36. public Action<WindowState> WindowStateChanged { get; set; }
  37. public WindowStub(IWindowImpl parent = null)
  38. {
  39. if (parent != null)
  40. PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent,
  41. (_, size, __) =>
  42. {
  43. Resize(size);
  44. }));
  45. }
  46. public IRenderer CreateRenderer(IRenderRoot root) => new ImmediateRenderer(root);
  47. public void Dispose()
  48. {
  49. }
  50. public void Invalidate(Rect rect)
  51. {
  52. }
  53. public void SetInputRoot(IInputRoot inputRoot)
  54. {
  55. }
  56. public Point PointToClient(PixelPoint p) => p.ToPoint(1);
  57. public PixelPoint PointToScreen(Point p) => PixelPoint.FromPoint(p, 1);
  58. public void SetCursor(IPlatformHandle cursor)
  59. {
  60. }
  61. public void Show()
  62. {
  63. }
  64. public void Hide()
  65. {
  66. }
  67. public void BeginMoveDrag()
  68. {
  69. }
  70. public void BeginResizeDrag(WindowEdge edge)
  71. {
  72. }
  73. public void Activate()
  74. {
  75. }
  76. public void Resize(Size clientSize)
  77. {
  78. }
  79. public void Move(PixelPoint point)
  80. {
  81. }
  82. public IScreenImpl Screen { get; } = new ScreenStub();
  83. public void SetMinMaxSize(Size minSize, Size maxSize)
  84. {
  85. }
  86. public void SetTitle(string title)
  87. {
  88. }
  89. public void ShowDialog(IWindowImpl parent)
  90. {
  91. }
  92. public void SetSystemDecorations(bool enabled)
  93. {
  94. }
  95. public void SetIcon(IWindowIconImpl icon)
  96. {
  97. }
  98. public void ShowTaskbarIcon(bool value)
  99. {
  100. }
  101. public void CanResize(bool value)
  102. {
  103. }
  104. public void SetTopmost(bool value)
  105. {
  106. }
  107. public IPopupPositioner PopupPositioner { get; }
  108. }
  109. class ClipboardStub : IClipboard
  110. {
  111. public Task<string> GetTextAsync() => Task.FromResult("");
  112. public Task SetTextAsync(string text) => Task.CompletedTask;
  113. public Task ClearAsync() => Task.CompletedTask;
  114. }
  115. class CursorFactoryStub : IStandardCursorFactory
  116. {
  117. public IPlatformHandle GetCursor(StandardCursorType cursorType) => new PlatformHandle(IntPtr.Zero, "STUB");
  118. }
  119. class IconLoaderStub : IPlatformIconLoader
  120. {
  121. class IconStub : IWindowIconImpl
  122. {
  123. public void Save(Stream outputStream)
  124. {
  125. }
  126. }
  127. public IWindowIconImpl LoadIcon(string fileName) => new IconStub();
  128. public IWindowIconImpl LoadIcon(Stream stream) => new IconStub();
  129. public IWindowIconImpl LoadIcon(IBitmapImpl bitmap) => new IconStub();
  130. }
  131. class SystemDialogsStub : ISystemDialogImpl
  132. {
  133. public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) =>
  134. Task.FromResult((string[]) null);
  135. public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) =>
  136. Task.FromResult((string) null);
  137. }
  138. class ScreenStub : IScreenImpl
  139. {
  140. public int ScreenCount => 1;
  141. public IReadOnlyList<Screen> AllScreens { get; } =
  142. new Screen[] { new Screen(new PixelRect(0, 0, 4000, 4000), new PixelRect(0, 0, 4000, 4000), true) };
  143. }
  144. }