CheckBoxProperty.xaml.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFAnnotation.Form;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.Tool;
  5. using ComPDFKit.Tool.Help;
  6. using System;
  7. using System.Linq;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Media;
  11. using ComPDFKit.Tool.UndoManger;
  12. using ComPDFKitViewer.Helper;
  13. namespace ComPDFKit.Controls.PDFControl
  14. {
  15. public partial class CheckBoxProperty : UserControl
  16. {
  17. private CheckBoxParam widgetParam = null;
  18. private CPDFCheckBoxWidget cPDFAnnotation = null;
  19. private PDFViewControl pdfViewerControl = null;
  20. private CPDFDocument cPDFDocument = null;
  21. bool IsLoadedData = false;
  22. public CheckBoxProperty()
  23. {
  24. InitializeComponent();
  25. }
  26. #region Loaded
  27. public void SetProperty(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
  28. {
  29. widgetParam = (CheckBoxParam)annotParam;
  30. cPDFAnnotation = (CPDFCheckBoxWidget)annotation;
  31. pdfViewerControl = cPDFViewer;
  32. cPDFDocument = doc;
  33. }
  34. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  35. {
  36. FieldNameText.Text = widgetParam.FieldName;
  37. FormFieldCmb.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
  38. BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
  39. BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
  40. CheckButtonStyleCmb.SelectedIndex = (int)widgetParam.CheckStyle;
  41. chkSelected.IsChecked = widgetParam.IsChecked;
  42. IsLoadedData = true;
  43. }
  44. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  45. {
  46. IsLoadedData = false;
  47. }
  48. #endregion
  49. private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
  50. {
  51. if (IsLoadedData)
  52. {
  53. string text = (sender as TextBox).Text;
  54. if(cPDFAnnotation.GetFieldName() != text)
  55. {
  56. CheckBoxHistory history = new CheckBoxHistory();
  57. history.Action = HistoryAction.Update;
  58. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  59. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  60. cPDFAnnotation.SetFieldName(text);
  61. pdfViewerControl.UpdateAnnotFrame();
  62. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  63. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  64. }
  65. pdfViewerControl.UpdateAnnotFrame();
  66. }
  67. }
  68. private void FormFieldCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  69. {
  70. if (IsLoadedData)
  71. {
  72. CheckBoxHistory history = new CheckBoxHistory();
  73. history.Action = HistoryAction.Update;
  74. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  75. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  76. cPDFAnnotation.SetFlags( ParamConverter.GetFormFlags((ParamConverter.FormField)(sender as ComboBox).SelectedIndex, cPDFAnnotation));
  77. pdfViewerControl.UpdateAnnotFrame();
  78. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  79. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  80. }
  81. }
  82. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  83. {
  84. if (IsLoadedData)
  85. {
  86. byte[] Color = new byte[3];
  87. Color[0] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.R;
  88. Color[1] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.G;
  89. Color[2] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.B;
  90. byte[] oldColor = new byte[3];
  91. cPDFAnnotation.GetWidgetBorderRGBColor(ref oldColor);
  92. if (!oldColor.SequenceEqual(Color))
  93. {
  94. CheckBoxHistory history = new CheckBoxHistory();
  95. history.Action = HistoryAction.Update;
  96. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  97. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  98. cPDFAnnotation.SetWidgetBorderRGBColor(Color);
  99. pdfViewerControl.UpdateAnnotFrame();
  100. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  101. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  102. }
  103. }
  104. }
  105. private void BackgroundColorPickerControl_ColorChanged(object sender, EventArgs e)
  106. {
  107. if (IsLoadedData)
  108. {
  109. byte[] Color = new byte[3];
  110. Color[0] = ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color.R;
  111. Color[1] = ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color.G;
  112. Color[2] = ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color.B;
  113. byte[] oldColor = new byte[3];
  114. cPDFAnnotation.GetWidgetBgRGBColor(ref oldColor);
  115. if (!oldColor.SequenceEqual(Color))
  116. {
  117. CheckBoxHistory history = new CheckBoxHistory();
  118. history.Action = HistoryAction.Update;
  119. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  120. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  121. cPDFAnnotation.SetWidgetBgRGBColor(Color);
  122. pdfViewerControl.UpdateAnnotFrame();
  123. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  124. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  125. }
  126. }
  127. }
  128. private void CheckButtonStyleCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  129. {
  130. if (IsLoadedData)
  131. {
  132. C_CHECK_STYLE style = (C_CHECK_STYLE)(sender as ComboBox).SelectedIndex;
  133. if (cPDFAnnotation.GetWidgetCheckStyle() != style)
  134. {
  135. CheckBoxHistory history = new CheckBoxHistory();
  136. history.Action = HistoryAction.Update;
  137. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  138. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  139. cPDFAnnotation.SetWidgetCheckStyle(style);
  140. pdfViewerControl.UpdateAnnotFrame();
  141. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  142. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  143. }
  144. }
  145. }
  146. private void chkSelected_Checked(object sender, RoutedEventArgs e)
  147. {
  148. if (IsLoadedData)
  149. {
  150. if (!cPDFAnnotation.IsChecked())
  151. {
  152. CheckBoxHistory history = new CheckBoxHistory();
  153. history.Action = HistoryAction.Update;
  154. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  155. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  156. cPDFAnnotation.SetChecked(true);
  157. pdfViewerControl.UpdateAnnotFrame();
  158. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  159. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  160. }
  161. }
  162. }
  163. private void chkSelected_Unchecked(object sender, RoutedEventArgs e)
  164. {
  165. if (IsLoadedData)
  166. {
  167. if (cPDFAnnotation.IsChecked())
  168. {
  169. CheckBoxHistory history = new CheckBoxHistory();
  170. history.Action = HistoryAction.Update;
  171. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  172. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  173. cPDFAnnotation.SetChecked(false);
  174. pdfViewerControl.UpdateAnnotFrame();
  175. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  176. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  177. }
  178. }
  179. }
  180. }
  181. }