MapObject.PreviewExt.cs 3.1 KB

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