SignatureProperty.xaml.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.Windows;
  7. using System.Windows.Controls;
  8. using ComPDFKit.Tool.UndoManger;
  9. using ComPDFKitViewer.Helper;
  10. namespace ComPDFKit.Controls.PDFControl
  11. {
  12. public partial class SignatureProperty : UserControl
  13. {
  14. private SignatureParam widgetParam = null;
  15. private CPDFSignatureWidget cPDFAnnotation = null;
  16. private PDFViewControl pdfViewerControl = null;
  17. private CPDFDocument cPDFDocument = null;
  18. bool IsLoadedData = false;
  19. public SignatureProperty()
  20. {
  21. InitializeComponent();
  22. }
  23. public void SetProperty(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
  24. {
  25. widgetParam = (SignatureParam)annotParam;
  26. cPDFAnnotation = (CPDFSignatureWidget)annotation;
  27. pdfViewerControl = cPDFViewer;
  28. cPDFDocument = doc;
  29. }
  30. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  31. {
  32. FormFieldCmb.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
  33. IsLoadedData = true;
  34. }
  35. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  36. {
  37. IsLoadedData = false;
  38. }
  39. private void FormFieldCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  40. {
  41. if (IsLoadedData)
  42. {
  43. var history = GetNewHistory();
  44. cPDFAnnotation.SetFlags(ParamConverter.GetFormFlags((ParamConverter.FormField)(sender as ComboBox).SelectedIndex, cPDFAnnotation));
  45. pdfViewerControl.UpdateAnnotFrame();
  46. AddHistory(history);
  47. }
  48. }
  49. private SignatureHistory GetNewHistory()
  50. {
  51. SignatureHistory history = new SignatureHistory();
  52. history.Action = HistoryAction.Update;
  53. history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
  54. history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  55. return history;
  56. }
  57. private void AddHistory(SignatureHistory history)
  58. {
  59. history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
  60. pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
  61. }
  62. }
  63. }