using ComPDFKit.PDFDocument;
using Compdfkit_Tools.Data;
using Compdfkit_Tools.Helper;
using Compdfkit_Tools.PDFControl;
using ComPDFKitViewer;
using ComPDFKitViewer.AnnotEvent;
using ComPDFKitViewer.PdfViewer;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace Annotations
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window, INotifyPropertyChanged
{
private PDFViewControl passwordViewer;
private PDFViewControl pdfViewControl;
private CPDFAnnotationControl pdfAnnotationControl = null;
private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
public bool CanSave
{
get
{
if (pdfViewControl != null && pdfViewControl.PDFView != null)
{
return pdfViewControl.PDFView.UndoManager.CanSave;
}
return false;
}
}
public bool CanUndo
{
get
{
if (pdfViewControl != null && pdfViewControl.PDFView != null)
{
return pdfViewControl.PDFView.UndoManager.CanUndo;
}
return false;
}
}
public bool CanRedo
{
get
{
if (pdfViewControl != null && pdfViewControl.PDFView != null)
{
return pdfViewControl.PDFView.UndoManager.CanRedo;
}
return false;
}
}
public event PropertyChangedEventHandler PropertyChanged;
public ICommand CloseTabCommand;
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
pdfAnnotationControl = new CPDFAnnotationControl();
BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
LoadDefaultDocument();
}
private void LoadDocument()
{
pdfViewControl.PDFView?.Load();
pdfViewControl.PDFView?.SetShowLink(true);
PDFGrid.Child = pdfViewControl;
pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
pdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
pdfViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
pdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
pdfViewControl.PDFView.SetFormFieldHighlight(true);
PasswordUI.Closed -= PasswordUI_Closed;
PasswordUI.Canceled -= PasswordUI_Canceled;
PasswordUI.Confirmed -= PasswordUI_Confirmed;
PasswordUI.Closed += PasswordUI_Closed;
PasswordUI.Canceled += PasswordUI_Canceled;
PasswordUI.Confirmed += PasswordUI_Confirmed;
pdfViewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
ViewSettingBtn.IsChecked = false;
PropertyContainer.Child = null;
PropertyContainer.Visibility = Visibility.Collapsed;
InitialPDFViewControl(pdfViewControl);
FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
}
private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
{
PropertyContainer.Child = pdfAnnotationControl;
pdfAnnotationControl.SetAnnotEventData(e);
}
private void PDFView_AnnotEditHandler(object sender, List e)
{
BotaSideTool.LoadAnnotationList();
}
private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(e.PropertyName);
}
private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
{
switch (e.CommandType)
{
case CommandType.Context:
e.Handle = true;
if (e.CommandTarget == TargetType.Annot)
{
e.Handle = true;
e.PopupMenu = new ContextMenu();
if (e.PressOnLink && AnnotationBarControl.CurrentMode == "Link")
{
e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
MenuItem propertyMenu = new MenuItem();
propertyMenu = new MenuItem();
propertyMenu.Header = "Edit";
WeakEventManager