using compdfkit_tools.Common;
using compdfkit_tools.Data;
using ComPDFKitViewer.AnnotEvent;
using ComPDFKitViewer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace compdfkit_tools.PDFControlUI
{
///
/// CPDFNoteUI.xaml 的交互逻辑
///
public partial class CPDFNoteUI : UserControl
{
public event EventHandler PropertyChanged;
internal AnnotAttribEvent annotAttribEvent { get;private set; }
public CPDFNoteUI()
{
InitializeComponent();
ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
}
private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
{
if (annotAttribEvent == null)
{
PropertyChanged?.Invoke(this, GetNoteData());
}
else
{
annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)ColorPickerControl.Brush).Color);
annotAttribEvent.UpdateAnnot();
}
CPDFAnnotationPreviewerControl.DrawNotePreview(GetNoteData());
}
private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (annotAttribEvent == null)
{
PropertyChanged?.Invoke(this, GetNoteData());
}
else
{
annotAttribEvent.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
annotAttribEvent.UpdateAnnot();
}
}
public void SetPresentAnnotAttrib(AnnotAttribEvent annotAttribEvent)
{
this.annotAttribEvent = null;
ColorPickerControl.Brush = new SolidColorBrush((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
NoteTextBox.Text = (string)annotAttribEvent.Attribs[AnnotAttrib.NoteText];
this.annotAttribEvent = annotAttribEvent;
if (annotAttribEvent.Attribs != null && annotAttribEvent.Attribs.ContainsKey(AnnotAttrib.Color))
{
ColorPickerControl.SetCheckedForColor((Color)annotAttribEvent.Attribs[AnnotAttrib.Color]);
}
}
public CPDFNoteData GetNoteData()
{
CPDFNoteData pdfNoteData = new CPDFNoteData();
pdfNoteData.AnnotationType = CPDFAnnotationType.Note;
pdfNoteData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
pdfNoteData.Note = NoteTextBox.Text;
return pdfNoteData;
}
}
}