MapObject.PreviewExt.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace FastReport.Map
  5. {
  6. partial class MapObject
  7. {
  8. #region Fields
  9. private bool isPanning;
  10. private bool panned;
  11. private Point lastMousePoint;
  12. private bool needPreviewPageModify;
  13. private ShapeBase hotPoint;
  14. #endregion // Fields
  15. #region Properties
  16. internal ShapeBase HotPoint
  17. {
  18. get { return hotPoint; }
  19. set
  20. {
  21. if (hotPoint != value)
  22. Page.Refresh();
  23. hotPoint = value;
  24. }
  25. }
  26. #endregion
  27. #region Preview mouse support
  28. /// <inheritdoc/>
  29. public override void OnMouseDown(MouseEventArgs e)
  30. {
  31. base.OnMouseDown(e);
  32. lastMousePoint = e.Location;
  33. isPanning = true;
  34. panned = false;
  35. }
  36. /// <inheritdoc/>
  37. public override void OnMouseMove(MouseEventArgs e)
  38. {
  39. base.OnMouseMove(e);
  40. if (!IsEmpty)
  41. {
  42. if (isPanning)
  43. {
  44. int deltaX = e.X - lastMousePoint.X;
  45. int deltaY = e.Y - lastMousePoint.Y;
  46. if (Math.Abs(deltaX) > 3 || Math.Abs(deltaY) > 3)
  47. {
  48. OffsetX += deltaX / Zoom;
  49. OffsetY += deltaY / Zoom;
  50. panned = true;
  51. lastMousePoint = e.Location;
  52. needPreviewPageModify = true;
  53. Page.Refresh();
  54. }
  55. }
  56. else
  57. {
  58. if (Hyperlink.Kind == HyperlinkKind.DetailPage || Hyperlink.Kind == HyperlinkKind.DetailReport)
  59. {
  60. foreach (MapLayer layer in Layers)
  61. {
  62. ShapeBase shape = layer.HitTest(new PointF(e.X + AbsLeft, e.Y + AbsTop));
  63. if (shape != null && !shape.IsValueEmpty)
  64. {
  65. HotPoint = shape;
  66. Hyperlink.Value = HotPoint.SpatialValue;
  67. Cursor = Cursors.Hand;
  68. return;
  69. }
  70. }
  71. HotPoint = null;
  72. Hyperlink.Value = "";
  73. Cursor = Cursors.Default;
  74. }
  75. }
  76. }
  77. }
  78. /// <inheritdoc/>
  79. public override void OnMouseUp(MouseEventArgs e)
  80. {
  81. base.OnMouseUp(e);
  82. // prevent hyperlink invoke while panning
  83. if (panned)
  84. Hyperlink.Value = "";
  85. isPanning = false;
  86. panned = false;
  87. }
  88. /// <inheritdoc/>
  89. public override void OnMouseWheel(MouseEventArgs e)
  90. {
  91. base.OnMouseWheel(e);
  92. if (e.Delta < 0)
  93. ZoomOut();
  94. else
  95. ZoomIn();
  96. needPreviewPageModify = true;
  97. }
  98. /// <inheritdoc/>
  99. public override void OnMouseEnter(EventArgs e)
  100. {
  101. base.OnMouseEnter(e);
  102. needPreviewPageModify = false;
  103. }
  104. /// <inheritdoc/>
  105. public override void OnMouseLeave(EventArgs e)
  106. {
  107. base.OnMouseLeave(e);
  108. HotPoint = null;
  109. if (needPreviewPageModify)
  110. Page.Modify();
  111. }
  112. #endregion
  113. }
  114. }