ControlAdapter.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // "Therefore those skilled at the unorthodox
  2. // are infinite as heaven and earth,
  3. // inexhaustible as the great rivers.
  4. // When they come to an end,
  5. // they begin again,
  6. // like the days and months;
  7. // they die and are reborn,
  8. // like the four seasons."
  9. //
  10. // - Sun Tsu,
  11. // "The Art of War"
  12. using Perspex.Controls;
  13. using Perspex.Controls.Html;
  14. using Perspex.Input;
  15. using TheArtOfDev.HtmlRenderer.Adapters;
  16. using TheArtOfDev.HtmlRenderer.Adapters.Entities;
  17. using TheArtOfDev.HtmlRenderer.Core.Utils;
  18. using TheArtOfDev.HtmlRenderer.Perspex.Utilities;
  19. // ReSharper disable ConvertPropertyToExpressionBody
  20. namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters
  21. {
  22. /// <summary>
  23. /// Adapter for Perspex Control for core.
  24. /// </summary>
  25. internal sealed class ControlAdapter : RControl
  26. {
  27. /// <summary>
  28. /// the underline Perspex control.
  29. /// </summary>
  30. private readonly Control _control;
  31. /// <summary>
  32. /// Init.
  33. /// </summary>
  34. public ControlAdapter(Control control)
  35. : base(PerspexAdapter.Instance)
  36. {
  37. ArgChecker.AssertArgNotNull(control, "control");
  38. _control = control;
  39. }
  40. /// <summary>
  41. /// Get the underline Perspex control
  42. /// </summary>
  43. public Control Control
  44. {
  45. get { return _control; }
  46. }
  47. public override RPoint MouseLocation
  48. {
  49. get
  50. {
  51. return Util.Convert(MouseDevice.Instance.GetPosition(_control));
  52. }
  53. }
  54. private bool _leftMouseButton;
  55. public override bool LeftMouseButton => (_control as HtmlControl)?.LeftMouseButton ?? false;
  56. public override bool RightMouseButton
  57. {
  58. get
  59. {
  60. return false;
  61. //TODO: Implement right mouse click
  62. //return Mouse.RightButton == MouseButtonState.Pressed;
  63. }
  64. }
  65. public override void SetCursorDefault()
  66. {
  67. _control.Cursor = new Cursor(StandardCursorType.Arrow);
  68. }
  69. public override void SetCursorHand()
  70. {
  71. _control.Cursor = new Cursor(StandardCursorType.Hand);
  72. }
  73. public override void SetCursorIBeam()
  74. {
  75. _control.Cursor = new Cursor(StandardCursorType.Ibeam);
  76. }
  77. public override void DoDragDropCopy(object dragDropData)
  78. {
  79. //TODO: Implement DragDropCopy
  80. //DragDrop.DoDragDrop(_control, dragDropData, DragDropEffects.Copy);
  81. }
  82. public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
  83. {
  84. using (var g = new GraphicsAdapter())
  85. {
  86. g.MeasureString(str, font, maxWidth, out charFit, out charFitWidth);
  87. }
  88. }
  89. public override void Invalidate()
  90. {
  91. _control.InvalidateVisual();
  92. }
  93. }
  94. }