CPDFViewerTool.AnnotEdit.cs 4.8 KB

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