CPDFNoteUI.xaml.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Compdfkit_Tools.Common;
  2. using Compdfkit_Tools.Data;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using ComPDFKitViewer;
  5. using System;
  6. using System.Windows.Controls;
  7. using System.Windows.Media;
  8. namespace Compdfkit_Tools.PDFControlUI
  9. {
  10. public partial class CPDFNoteUI : UserControl
  11. {
  12. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  13. internal AnnotAttribEvent annotAttribEvent { get;private set; }
  14. public CPDFNoteUI()
  15. {
  16. InitializeComponent();
  17. ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
  18. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  19. ColorPickerControl.SetCheckedForColor(GetNoteData().BorderColor);
  20. }
  21. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  22. {
  23. if (annotAttribEvent == null)
  24. {
  25. PropertyChanged?.Invoke(this, GetNoteData());
  26. }
  27. else
  28. {
  29. annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)ColorPickerControl.Brush).Color);
  30. annotAttribEvent.UpdateAnnot();
  31. }
  32. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  33. }
  34. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  35. {
  36. if (annotAttribEvent == null)
  37. {
  38. PropertyChanged?.Invoke(this, GetNoteData());
  39. }
  40. else
  41. {
  42. annotAttribEvent.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
  43. annotAttribEvent.UpdateAnnot();
  44. }
  45. }
  46. public void SetPresentAnnotAttrib(AnnotAttribEvent annotAttribEvent)
  47. {
  48. this.annotAttribEvent = null;
  49. NoteTextBox.Text = (string)annotAttribEvent.Attribs[AnnotAttrib.NoteText];
  50. this.annotAttribEvent = annotAttribEvent;
  51. if (annotAttribEvent.Attribs != null && annotAttribEvent.Attribs.ContainsKey(AnnotAttrib.Color))
  52. {
  53. ColorPickerControl.Loaded += ColorPickerControl_Loaded;
  54. }
  55. }
  56. private void ColorPickerControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
  57. {
  58. ColorPickerControl.SetCheckedForColor((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
  59. ColorPickerControl.Loaded -= ColorPickerControl_Loaded;
  60. }
  61. public CPDFNoteData GetNoteData()
  62. {
  63. CPDFNoteData pdfNoteData = new CPDFNoteData();
  64. pdfNoteData.AnnotationType = CPDFAnnotationType.Note;
  65. pdfNoteData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  66. pdfNoteData.Note = NoteTextBox.Text;
  67. return pdfNoteData;
  68. }
  69. }
  70. }