CPDFNoteUI.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  20. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  21. {
  22. if (annotAttribEvent == null)
  23. {
  24. PropertyChanged?.Invoke(this, GetNoteData());
  25. }
  26. else
  27. {
  28. annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)ColorPickerControl.Brush).Color);
  29. annotAttribEvent.UpdateAnnot();
  30. }
  31. CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
  32. }
  33. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  34. {
  35. if (annotAttribEvent == null)
  36. {
  37. PropertyChanged?.Invoke(this, GetNoteData());
  38. }
  39. else
  40. {
  41. annotAttribEvent.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
  42. annotAttribEvent.UpdateAnnot();
  43. }
  44. }
  45. public void SetPresentAnnotAttrib(AnnotAttribEvent annotAttribEvent)
  46. {
  47. this.annotAttribEvent = null;
  48. ColorPickerControl.Brush = new SolidColorBrush((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
  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.SetCheckedForColor((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
  54. }
  55. }
  56. public CPDFNoteData GetNoteData()
  57. {
  58. CPDFNoteData pdfNoteData = new CPDFNoteData();
  59. pdfNoteData.AnnotationType = CPDFAnnotationType.Note;
  60. pdfNoteData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  61. pdfNoteData.Note = NoteTextBox.Text;
  62. return pdfNoteData;
  63. }
  64. }
  65. }