ReplyStatusControl.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 2 H16 V16 H2 V2 M4 4 L14 14 M14 4 L4 14"),
  64. Stroke = Brushes.Black,
  65. StrokeThickness = 1,
  66. Fill = Brushes.Transparent
  67. },
  68. Tag = CPDFAnnotationState.C_ANNOTATION_CANCELLED
  69. },
  70. new PathMenuItem
  71. {
  72. Header = "Completed",
  73. IconPath = new Path
  74. {
  75. Data = Geometry.Parse("M2 2 H16 V16 H2 V2 M5 9 L8 12 L14 6"),
  76. Stroke = Brushes.Black,
  77. StrokeThickness = 1,
  78. Fill = Brushes.Transparent
  79. },
  80. Tag = CPDFAnnotationState.C_ANNOTATION_COMPLETED
  81. },
  82. new PathMenuItem
  83. {
  84. Header = "None",
  85. IconPath = new Path
  86. {
  87. Data = Geometry.Parse("M2 2 H16 V16 H2 V2 M5 9 H13"),
  88. Stroke = Brushes.Black,
  89. StrokeThickness = 1,
  90. Fill = Brushes.Transparent
  91. },
  92. Tag = CPDFAnnotationState.C_ANNOTATION_NONE
  93. },
  94. };
  95. Style style = FindResource("MenuItemStyle") as Style;
  96. foreach (var item in PathItems)
  97. {
  98. item.IconPath.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#43474D"));
  99. item.IconPath.StrokeThickness = 1.5;
  100. item.IconPath.StrokeDashCap = PenLineCap.Round;
  101. item.IconPath.StrokeDashArray = new DoubleCollection { 2, 0 };
  102. item.IconPath.HorizontalAlignment = HorizontalAlignment.Center;
  103. item.IconPath.VerticalAlignment = VerticalAlignment.Center;
  104. item.Style = style;
  105. item.Click += MenuItem_Click;
  106. IconMenu.Items.Add(item);
  107. }
  108. }
  109. public void SetButtonIcon(CPDFAnnotationState status)
  110. {
  111. var pathItem = PathItems.Find(x => (CPDFAnnotationState)x.Tag == status);
  112. if (pathItem == null) return;
  113. ButtonIcon.Children.Clear();
  114. ButtonIcon.Children.Add(pathItem.IconPath.Clone());
  115. }
  116. private void MenuItem_Click(object sender, RoutedEventArgs e)
  117. {
  118. if (sender is MenuItem menuItem)
  119. {
  120. if (menuItem is PathMenuItem pathItem)
  121. {
  122. ButtonIcon.Children.Clear();
  123. ButtonIcon.Children.Add(pathItem.IconPath.Clone());
  124. ReplyStatusChanged?.Invoke(this, (CPDFAnnotationState)pathItem.Tag);
  125. }
  126. }
  127. }
  128. }
  129. public class PathMenuItem : MenuItem
  130. {
  131. public static readonly DependencyProperty IconPathProperty =
  132. DependencyProperty.Register(nameof(IconPath), typeof(Path), typeof(PathMenuItem));
  133. public Path IconPath
  134. {
  135. get
  136. {
  137. var a = (Path)GetValue(IconPathProperty);
  138. return a;
  139. }
  140. set { SetValue(IconPathProperty, value); }
  141. }
  142. }
  143. public static class PathExtensions
  144. {
  145. public static Path Clone(this Path original)
  146. {
  147. return new Path
  148. {
  149. Data = original.Data?.Clone(),
  150. Fill = original.Fill?.Clone(),
  151. Stroke = original.Stroke?.Clone(),
  152. StrokeThickness = original.StrokeThickness,
  153. StrokeDashArray = original.StrokeDashArray?.Clone(),
  154. StrokeDashCap = original.StrokeDashCap,
  155. HorizontalAlignment = original.HorizontalAlignment,
  156. VerticalAlignment = original.VerticalAlignment
  157. };
  158. }
  159. }
  160. }