ReplyStatusControl.xaml.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using ComPDFKit.PDFAnnotation;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Media;
  7. using System.Windows.Shapes;
  8. namespace ComPDFKit.Controls.PDFControlUI
  9. {
  10. /// <summary>
  11. /// Interaction logic for ReplyStatusControl.xaml
  12. /// </summary>
  13. public partial class ReplyStatusControl : UserControl
  14. {
  15. public List<PathMenuItem> PathItems;
  16. public event EventHandler<CPDFAnnotationState> ReplyStatusChanged;
  17. public static readonly DependencyProperty StatusProperty =
  18. DependencyProperty.Register(nameof(Status), typeof(CPDFAnnotationState), typeof(ReplyStatusControl),
  19. new PropertyMetadata(CPDFAnnotationState.C_ANNOTATION_NONE, OnStatusChanged));
  20. public CPDFAnnotationState Status
  21. {
  22. get => (CPDFAnnotationState)GetValue(StatusProperty);
  23. set => SetValue(StatusProperty, value);
  24. }
  25. private static void OnStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  26. {
  27. var control = d as ReplyStatusControl;
  28. var newState = (CPDFAnnotationState)e.NewValue;
  29. control.SetButtonIcon(newState);
  30. }
  31. public ReplyStatusControl()
  32. {
  33. InitializeComponent();
  34. InitPathItems();
  35. }
  36. private void InitPathItems()
  37. {
  38. PathItems = new List<PathMenuItem>
  39. {
  40. new PathMenuItem
  41. {
  42. Header = "Accepted",
  43. IconPath = new Path
  44. {
  45. Data = Geometry.Parse("M6.58308 8.44989L9.4497 1.99999C10.0199 1.99999 10.5668 2.22651 10.97 2.6297C11.3732 3.0329 11.5997 3.57975 11.5997 4.14996V7.01658H15.6559C15.8637 7.01422 16.0695 7.05707 16.259 7.14215C16.4486 7.22722 16.6174 7.3525 16.7537 7.50929C16.8901 7.66608 16.9907 7.85063 17.0486 8.05017C17.1066 8.24971 17.1204 8.45946 17.0892 8.66488L16.1003 15.1148C16.0484 15.4565 15.8748 15.7681 15.6114 15.992C15.348 16.2158 15.0126 16.337 14.6669 16.3331H6.58308M6.58308 8.44989V16.3331M6.58308 8.44989H4.66961C4.26402 8.44271 3.8699 8.58471 3.56209 8.84893C3.25427 9.11315 3.05419 9.48119 2.99981 9.88319V14.8998C3.05419 15.3018 3.25427 15.6698 3.56209 15.934C3.8699 16.1983 4.26402 16.3403 4.66961 16.3331H6.58308"),
  46. },
  47. Tag = CPDFAnnotationState.C_ANNOTATION_ACCEPTED
  48. },
  49. new PathMenuItem
  50. {
  51. Header = "Rejected",
  52. IconPath = new Path
  53. {
  54. Data = Geometry.Parse("M11.5224 8.88346L8.65577 15.3333C8.08556 15.3333 7.53871 15.1068 7.13551 14.7036C6.73232 14.3004 6.5058 13.7536 6.5058 13.1834V10.3168H2.44954C2.24178 10.3191 2.03598 10.2763 1.84642 10.1912C1.65686 10.1061 1.48807 9.98085 1.35173 9.82406C1.21539 9.66727 1.11477 9.48271 1.05684 9.28317C0.998906 9.08363 0.985051 8.87389 1.01623 8.66846L2.00521 2.21857C2.05704 1.87679 2.23065 1.56526 2.49404 1.34138C2.75743 1.1175 3.09286 0.996351 3.43852 1.00026H11.5224M11.5224 8.88346V1.00026M11.5224 8.88346H13.4359C13.8415 8.89063 14.2356 8.74863 14.5434 8.48441C14.8512 8.22019 15.0513 7.85215 15.1057 7.45015V2.43357C15.0513 2.03157 14.8512 1.66352 14.5434 1.39931C14.2356 1.13509 13.8415 0.993086 13.4359 1.00026H11.5224"),
  55. },
  56. Tag = CPDFAnnotationState.C_ANNOTATION_REJECTED
  57. },
  58. new PathMenuItem
  59. {
  60. Header = "Cancelled",
  61. IconPath = new Path
  62. {
  63. Data = Geometry.Parse("M2 2H13.5V13.5H2V2ZM0.5 0.5H2H13.5H15V2V13.5V15H13.5H2H0.5V13.5V2V0.5ZM5.56066 4.5L6.09099 5.03033L8.00165 6.94099L9.91231 5.03033L10.4426 4.5L11.5033 5.56066L10.973 6.09099L9.06231 8.00165L10.973 9.91232L11.5033 10.4426L10.4426 11.5033L9.91231 10.973L8.00165 9.06231L6.09099 10.973L5.56066 11.5033L4.5 10.4426L5.03033 9.91232L6.94099 8.00165L5.03033 6.09099L4.5 5.56066L5.56066 4.5Z"),
  64. },
  65. Tag = CPDFAnnotationState.C_ANNOTATION_CANCELLED
  66. },
  67. new PathMenuItem
  68. {
  69. Header = "Completed",
  70. IconPath = new Path
  71. {
  72. Data = Geometry.Parse("M2 2H13.5V13.5H2V2ZM0.5 0.5H2H13.5H15V2V13.5V15H13.5H2H0.5V13.5V2V0.5ZM11.6441 6.40148L12.1745 5.87115L11.1138 4.81049L10.5835 5.34082L6.87115 9.05313L5.53033 7.71231L5 7.18198L3.93934 8.24264L4.46967 8.77297L6.34082 10.6441L6.87115 11.1745L7.40148 10.6441L11.6441 6.40148Z"),
  73. },
  74. Tag = CPDFAnnotationState.C_ANNOTATION_COMPLETED
  75. },
  76. new PathMenuItem
  77. {
  78. Header = "None",
  79. IconPath = new Path
  80. {
  81. Data = Geometry.Parse("M2 2H13.5V13.5H2V2ZM0.5 0.5H2H13.5H15V2V13.5V15H13.5H2H0.5V13.5V2V0.5ZM5 7.25H4.25V8.75H5H11H11.75V7.25H11H5Z"),
  82. },
  83. Tag = CPDFAnnotationState.C_ANNOTATION_NONE
  84. }
  85. };
  86. Style style = FindResource("MenuItemStyle") as Style;
  87. foreach (var item in PathItems)
  88. {
  89. item.IconPath.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#43474D"));
  90. item.IconPath.StrokeThickness = 1.5;
  91. item.IconPath.StrokeDashCap = PenLineCap.Round;
  92. item.IconPath.StrokeDashArray = new DoubleCollection { 2, 0 };
  93. item.IconPath.HorizontalAlignment = HorizontalAlignment.Center;
  94. item.IconPath.VerticalAlignment = VerticalAlignment.Center;
  95. item.Style = style;
  96. item.Click += MenuItem_Click;
  97. IconMenu.Items.Add(item);
  98. }
  99. }
  100. public void SetButtonIcon(CPDFAnnotationState status)
  101. {
  102. var pathItem = PathItems.Find(x => (CPDFAnnotationState)x.Tag == status);
  103. if (pathItem == null) return;
  104. ButtonIcon.Children.Clear();
  105. ButtonIcon.Children.Add(pathItem.IconPath.Clone());
  106. }
  107. private void MenuItem_Click(object sender, RoutedEventArgs e)
  108. {
  109. if (sender is MenuItem menuItem)
  110. {
  111. if (menuItem is PathMenuItem pathItem)
  112. {
  113. ButtonIcon.Children.Clear();
  114. ButtonIcon.Children.Add(pathItem.IconPath.Clone());
  115. ReplyStatusChanged?.Invoke(this, (CPDFAnnotationState)pathItem.Tag);
  116. }
  117. }
  118. }
  119. }
  120. public class PathMenuItem : MenuItem
  121. {
  122. public static readonly DependencyProperty IconPathProperty =
  123. DependencyProperty.Register(nameof(IconPath), typeof(Path), typeof(PathMenuItem));
  124. public Path IconPath
  125. {
  126. get
  127. {
  128. var a = (Path)GetValue(IconPathProperty);
  129. return a;
  130. }
  131. set { SetValue(IconPathProperty, value); }
  132. }
  133. }
  134. public static class PathExtensions
  135. {
  136. public static Path Clone(this Path original)
  137. {
  138. return new Path
  139. {
  140. Data = original.Data?.Clone(),
  141. Fill = original.Fill?.Clone(),
  142. Stroke = original.Stroke?.Clone(),
  143. StrokeThickness = original.StrokeThickness,
  144. StrokeDashArray = original.StrokeDashArray?.Clone(),
  145. StrokeDashCap = original.StrokeDashCap,
  146. HorizontalAlignment = original.HorizontalAlignment,
  147. VerticalAlignment = original.VerticalAlignment
  148. };
  149. }
  150. }
  151. }