RadioButtonProperty.xaml.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using ComPDFKit.PDFAnnotation.Form;
  2. using ComPDFKit.PDFAnnotation;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using ComPDFKit.PDFDocument;
  10. using ComPDFKit.Tool;
  11. using ComPDFKit.Tool.Help;
  12. using ComPDFKit.Tool.UndoManger;
  13. using ComPDFKitViewer.Helper;
  14. namespace Compdfkit_Tools.PDFControl
  15. {
  16. public partial class RadioButtonProperty : UserControl
  17. {
  18. private RadioButtonParam widgetParam = null;
  19. private CPDFRadioButtonWidget cPDFAnnotation = null;
  20. private PDFViewControl pdfViewerControl = null;
  21. private CPDFDocument cPDFDocument = null;
  22. bool IsLoadedData = false;
  23. public RadioButtonProperty()
  24. {
  25. InitializeComponent();
  26. }
  27. #region Loaded
  28. public void SetProperty(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
  29. {
  30. widgetParam = (RadioButtonParam)annotParam;
  31. cPDFAnnotation = (CPDFRadioButtonWidget)annotation;
  32. pdfViewerControl = cPDFViewer;
  33. cPDFDocument = doc;
  34. }
  35. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  36. {
  37. FieldNameText.Text = widgetParam.FieldName;
  38. FormFieldCmb.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
  39. BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
  40. BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
  41. RadioButtonStyleCmb.SelectedIndex = (int)widgetParam.CheckStyle;
  42. chkSelected.IsChecked = widgetParam.IsChecked;
  43. if (IsShowWarning())
  44. {
  45. WarningPanel.Visibility = Visibility.Collapsed;
  46. }
  47. else
  48. {
  49. WarningPanel.Visibility = Visibility.Visible;
  50. }
  51. IsLoadedData = true;
  52. }
  53. private bool IsShowWarning()
  54. {
  55. int count = 0;
  56. var page = cPDFDocument.PageAtIndex(pdfViewerControl.PDFViewTool.GetCPDFViewer().CurrentRenderFrame.PageIndex);
  57. List<CPDFAnnotation> annotList = page.GetAnnotations();
  58. if (annotList != null && annotList.Count > 0)
  59. {
  60. count = annotList.Where(x => x.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  61. .Cast<CPDFWidget>().Where(x => x.WidgetType == C_WIDGET_TYPE.WIDGET_RADIOBUTTON).Count();
  62. }
  63. return count>1;
  64. }
  65. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  66. {
  67. IsLoadedData = false;
  68. }
  69. #endregion
  70. private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
  71. {
  72. if (IsLoadedData)
  73. {
  74. var history = GetNewHistory();
  75. cPDFAnnotation.SetFieldName((sender as TextBox).Text);
  76. pdfViewerControl.UpdateAnnotFrame();
  77. AddHistory(history);
  78. }
  79. }
  80. private void FormFieldCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  81. {
  82. if (IsLoadedData)
  83. {
  84. var history = GetNewHistory();
  85. cPDFAnnotation.SetFlags(ParamConverter.GetFormFlags((ParamConverter.FormField)(sender as ComboBox).SelectedIndex, cPDFAnnotation));
  86. pdfViewerControl.UpdateAnnotFrame();
  87. AddHistory(history);
  88. }
  89. }
  90. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  91. {
  92. if (IsLoadedData)
  93. {
  94. var history = GetNewHistory();
  95. byte[] Color = new byte[3];
  96. Color[0] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.R;
  97. Color[1] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.G;
  98. Color[2] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.B;
  99. cPDFAnnotation.SetWidgetBorderRGBColor(Color);
  100. pdfViewerControl.UpdateAnnotFrame();
  101. AddHistory(history);
  102. }
  103. }
  104. private void BackgroundColorPickerControl_ColorChanged(object sender, EventArgs e)
  105. {
  106. if (IsLoadedData)
  107. {
  108. var history = GetNewHistory();
  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. cPDFAnnotation.SetWidgetBgRGBColor(Color);
  114. pdfViewerControl.UpdateAnnotFrame();
  115. AddHistory(history);
  116. }
  117. }
  118. private void RadioButtonStyleCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  119. {
  120. if (IsLoadedData)
  121. {
  122. var history = GetNewHistory();
  123. cPDFAnnotation.SetWidgetCheckStyle((C_CHECK_STYLE)(sender as ComboBox).SelectedIndex);
  124. pdfViewerControl.UpdateAnnotFrame();
  125. AddHistory(history);
  126. }
  127. }
  128. private void chkSelected_Checked(object sender, RoutedEventArgs e)
  129. {
  130. if (IsLoadedData)
  131. {
  132. var history = GetNewHistory();
  133. cPDFAnnotation.SetChecked(true);
  134. pdfViewerControl.UpdateAnnotFrame();
  135. AddHistory(history);
  136. }
  137. }
  138. private void chkSelected_Unchecked(object sender, RoutedEventArgs e)
  139. {
  140. if (IsLoadedData)
  141. {
  142. var history = GetNewHistory();
  143. cPDFAnnotation.SetChecked(false);
  144. pdfViewerControl.UpdateAnnotFrame();
  145. AddHistory(history);
  146. }
  147. }
  148. private RadioButtonHistory GetNewHistory()
  149. {
  150. RadioButtonHistory history = new RadioButtonHistory();
  151. history.Action = HistoryAction.Update;
  152. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  153. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  154. return history;
  155. }
  156. private void AddHistory(RadioButtonHistory history)
  157. {
  158. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  159. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  160. }
  161. }
  162. }