CPDFViewerTool.AnnotEdit.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using ComPDFKit.Tool.DrawTool;
  2. using ComPDFKit.Tool.Help;
  3. using ComPDFKit.Viewer.Layer;
  4. using ComPDFKitViewer.Layer;
  5. using System;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. namespace ComPDFKit.Tool
  10. {
  11. public partial class CPDFViewerTool
  12. {
  13. bool IsDrawEditAnnot = false;
  14. int annotEditViewTag = -1;
  15. public event EventHandler<SelectedAnnotData> AnnotEditDataChanging;
  16. public event EventHandler<SelectedAnnotData> AnnotEditDataChanged;
  17. public event EventHandler<object> AnnotChanged;
  18. private void InsertAnnotEditView()
  19. {
  20. int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
  21. CustomizeLayer customizeLayer = new CustomizeLayer();
  22. AnnotEdit annotEdit = new AnnotEdit(GetDefaultDrawParam());
  23. annotEdit.DataChanged += AnnotEdit_DataChanged;
  24. annotEdit.DataChanging += AnnotEdit_DataChanging;
  25. customizeLayer.Children.Add(annotEdit);
  26. PDFViewer.InsertView(selectedRectViewIndex, customizeLayer);
  27. annotEditViewTag = customizeLayer.GetResTag();
  28. }
  29. private void AnnotEdit_DataChanging(object sender, SelectedAnnotData e)
  30. {
  31. AnnotEditDataChanging?.Invoke(this, e);
  32. }
  33. private void AnnotEdit_DataChanged(object sender, SelectedAnnotData e)
  34. {
  35. AnnotEditDataChanged?.Invoke(this, e);
  36. }
  37. public void StartDrawEditAnnot()
  38. {
  39. Point point = Mouse.GetPosition(this);
  40. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  41. AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  42. if (annotEdit != null)
  43. {
  44. annotEdit.Draw();
  45. annotEdit.OnMouseLeftButtonDown(point);
  46. IsDrawEditAnnot = true;
  47. }
  48. }
  49. public bool DrawMoveEditAnnot()
  50. {
  51. bool DrawTag = false;
  52. Point point = Mouse.GetPosition(this);
  53. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  54. AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  55. if (annotEdit != null)
  56. {
  57. annotEdit.OnMouseMove(point, out DrawTag);
  58. if (DrawTag)
  59. {
  60. annotEdit.Draw();
  61. }
  62. }
  63. return DrawTag;
  64. }
  65. public void DrawEndEditAnnot()
  66. {
  67. Point point = Mouse.GetPosition(this);
  68. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  69. AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  70. if (annotEdit != null)
  71. {
  72. annotEdit.OnMouseLeftButtonUp(point);
  73. annotEdit.Draw();
  74. }
  75. }
  76. public void CleanEditAnnot(bool isDrawEditAnnot = false)
  77. {
  78. Point point = Mouse.GetPosition(this);
  79. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  80. AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  81. if (annotEdit != null)
  82. {
  83. annotEdit.ClearDraw();
  84. IsDrawEditAnnot = isDrawEditAnnot;
  85. }
  86. }
  87. internal void DrawEditAnnotLayer()
  88. {
  89. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  90. AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  91. if (annotEdit != null)
  92. {
  93. annotEdit.Draw();
  94. }
  95. }
  96. /// <summary>
  97. /// Press the mouse on the selected rectangle
  98. /// </summary>
  99. /// <returns></returns>
  100. private bool DrawEditAnnotDownEvent()
  101. {
  102. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  103. AnnotEdit selectedRect = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  104. if (selectedRect != null)
  105. {
  106. if (selectedRect.GetHitIndex(Mouse.GetPosition(this)) != -1)
  107. {
  108. return true;
  109. }
  110. }
  111. return false;
  112. }
  113. internal void SetEditAnnotObject()
  114. {
  115. if (cacheHitTestAnnot == null)
  116. {
  117. return;
  118. }
  119. Point point = Mouse.GetPosition(this);
  120. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  121. AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  122. if (annotEdit != null)
  123. {
  124. annotEdit.SetAnnotObject(cacheHitTestAnnot.GetAnnotData());
  125. }
  126. }
  127. public PointCollection SetEditAnnotPoint()
  128. {
  129. Point point = Mouse.GetPosition(this);
  130. BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
  131. AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
  132. if (annotEdit != null)
  133. {
  134. return annotEdit.GetActivePoints();
  135. }
  136. return null;
  137. }
  138. public bool GetIsDrawEditAnnot()
  139. {
  140. return IsDrawEditAnnot;
  141. }
  142. }
  143. }