using ComPDFKit.PDFDocument;
using compdfkit_tools.Annotation.PDFAnnotationControl;
using compdfkit_tools.PDFControl;
using ComPDFKitViewer;
using ComPDFKitViewer.PdfViewer;
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.Controls.Primitives;
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 annotation_ctrl_demo
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
private CPDFViewer pdfViewer=new CPDFViewer();
public MainWindow()
{
InitializeComponent();
TitleBarControl.Loaded += TitleBarControl_Loaded;
AnnotationBarControl.Loaded += AnnotationBarControl_Loaded;
ModeSelectorBarControl.ShowBOTAEvent += ModrSelectorBarControl_ShowBOTAEvent;
}
private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
{
AnnotationProperties[] annotationProperties = { AnnotationProperties.Highlight,AnnotationProperties.Underline, AnnotationProperties.Strikeout, AnnotationProperties.Squiggly, AnnotationProperties.Freetext, AnnotationProperties.Note, AnnotationProperties.Sharp, AnnotationProperties.Line, AnnotationProperties.Stamp, AnnotationProperties.Signature, AnnotationProperties.Link, AnnotationProperties.Sound};
AnnotationBarControl.InitAnnotationBar(annotationProperties);
AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
}
private void AnnotationBarControl_AnnotationPropertyChanged(object sender, string e)
{
UIElement propertyPanel = GetPropertyPanel();
if (propertyPanel == null)
{
CPDFAnnotationControl pdfAnnotationControl = new CPDFAnnotationControl();
pdfAnnotationControl.LoadAnnotationPanel(AnnotationProperties.Highlight);
SetPropertyPanel(pdfAnnotationControl);
}
ExpandPropertyPanel((sender as ToggleButton).IsChecked == true);
}
private void ModrSelectorBarControl_ShowBOTAEvent(object sender, EventArgs e)
{
UIElement botaTool = GetBotaTool();
if (botaTool == null)
{
CPDFBOTABarControl pdfBOTABarControl = new CPDFBOTABarControl(BOTATools.Outline | BOTATools.Thumbnail | BOTATools.Annotation | BOTATools.Search | BOTATools.Bookmark);
if (pdfViewer != null && pdfViewer.Document != null)
{
pdfBOTABarControl.InitWithPDFViewer(pdfViewer);
}
SetBotaTool(pdfBOTABarControl);
}
ExpandTool(ModeSelectorBarControl.BOTABarIsShowing == true);
}
private void LoadDocument()
{
pdfViewer.Load();
PDFGrid.Child = pdfViewer;
UIElement currentBotaTool = GetBotaTool();
if (currentBotaTool is CPDFBOTABarControl)
{
((CPDFBOTABarControl)currentBotaTool).InitWithPDFViewer(pdfViewer);
}
}
private void TitleBarControl_OpenFileEvent(object sender, string filePath)
{
pdfViewer?.CloseDocument();
pdfViewer?.InitDocument(filePath);
LoadDocument();
}
private void TitleBarControl_Loaded(object sender, RoutedEventArgs e)
{
TitleBarControl.OpenFileEvent += TitleBarControl_OpenFileEvent;
}
private UIElement GetPropertyPanel()
{
return PropertyPanelContainer.Child;
}
private UIElement GetBotaTool()
{
return BotaToolContainer.Child;
}
private void SetPropertyPanel(UIElement propertyPanel)
{
PropertyPanelContainer.Child = propertyPanel;
}
private void SetBotaTool(UIElement newChild)
{
BotaToolContainer.Child = newChild;
}
private void ExpandPropertyPanel(bool isExpand)
{
if (isExpand)
{
BodyGrid.ColumnDefinitions[4].Width = new GridLength(300);
}
else
{
BodyGrid.ColumnDefinitions[4].Width = new GridLength(0);
}
PropertyPanelContainer.Visibility = isExpand? Visibility.Visible : Visibility.Collapsed;
PropertyPanelSplitter.Visibility = isExpand? Visibility.Visible : Visibility.Collapsed;
}
///
/// 展开Bota工具
///
///
private void ExpandTool(bool isExpand)
{
if (isExpand)
{
BodyGrid.ColumnDefinitions[0].Width = new GridLength(300);
}
else
{
BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
}
BotaToolContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
BotaSplitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
}
}
}