|
@@ -1,6 +1,13 @@
|
|
|
-using System;
|
|
|
+using Compdfkit_Tools.Helper;
|
|
|
+using Compdfkit_Tools.PDFControl;
|
|
|
+using Compdfkit_Tools.PDFView;
|
|
|
+using ComPDFKitViewer;
|
|
|
+using ComPDFKitViewer.PdfViewer;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.ComponentModel;
|
|
|
using System.Linq;
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
@@ -18,13 +25,168 @@ namespace DigitalSignature
|
|
|
/// <summary>
|
|
|
/// MainWindow.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
- public partial class MainWindow : Window
|
|
|
+ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
|
{
|
|
|
+ private string currentMode = "Viewer";
|
|
|
+
|
|
|
+ private PDFViewControl pdfViewer;
|
|
|
+ private PDFViewControl passwordViewer;
|
|
|
+ private RegularViewerControl regularViewerControl = new RegularViewerControl();
|
|
|
+ private DigitalSignatureControl digitalSignatureControl = new DigitalSignatureControl();
|
|
|
+ private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
|
|
|
+ private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
|
|
|
+
|
|
|
+ private PanelState panelState = PanelState.GetInstance();
|
|
|
+
|
|
|
+ public event PropertyChangedEventHandler PropertyChanged;
|
|
|
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
+ {
|
|
|
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private bool _canSave = false;
|
|
|
+ public bool CanSave
|
|
|
+ {
|
|
|
+ get => _canSave;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _canSave = value;
|
|
|
+ OnPropertyChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool LeftToolPanelButtonIsChecked
|
|
|
+ {
|
|
|
+ get => panelState.IsLeftPanelExpand;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ panelState.IsLeftPanelExpand = value;
|
|
|
+ OnPropertyChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool RightToolPanelButtonIsChecked
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel);
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ panelState.RightPanel = (value) ? PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
|
|
|
+ OnPropertyChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool ViewSettingBtnIsChecked
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return (panelState.RightPanel == PanelState.RightPanelState.ViewSettings);
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ panelState.RightPanel = (value) ? PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
|
|
|
+ OnPropertyChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public MainWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ DataContext = this;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region Load Document
|
|
|
+ private void LoadDefaultDocument()
|
|
|
+ {
|
|
|
+ string defaultFilePath = "PDF32000_2008.pdf";
|
|
|
+ pdfViewer.PDFView.InitDocument(defaultFilePath);
|
|
|
+ LoadDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadCustomControl()
|
|
|
+ {
|
|
|
+ regularViewerControl.PdfViewControl = pdfViewer;
|
|
|
+ regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
|
|
|
+ regularViewerControl.SetBOTAContainer(null);
|
|
|
+ regularViewerControl.SetBOTAContainer(botaBarControl);
|
|
|
+ regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
|
|
|
+ PDFGrid.Child = regularViewerControl;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadDocument()
|
|
|
+ {
|
|
|
+ if (pdfViewer.PDFView.Document == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ pdfViewer.PDFView.Load();
|
|
|
+ pdfViewer.PDFView.SetShowLink(true);
|
|
|
+
|
|
|
+ pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
|
|
|
+ pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
|
|
|
+
|
|
|
+ pdfViewer.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;
|
|
|
+ ModeComboBox.SelectedIndex = 0;
|
|
|
+ LoadCustomControl();
|
|
|
+ pdfViewer.PDFView.ChangeFitMode(FitMode.FitWidth);
|
|
|
+ CPDFSaclingControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ regularViewerControl.IsActive = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
|
|
|
+ {
|
|
|
+ if (e.Key == "Zoom")
|
|
|
+ {
|
|
|
+ CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordUI_Confirmed(object sender, string e)
|
|
|
+ {
|
|
|
+ if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ passwordViewer.PDFView.Document.UnlockWithPassword(e);
|
|
|
+ if (passwordViewer.PDFView.Document.IsLocked == false)
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowError("", Visibility.Collapsed);
|
|
|
+ PasswordUI.ClearPassword();
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ pdfViewer = passwordViewer;
|
|
|
+ LoadDocument();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordUI_Canceled(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
|
|
|
+ private void PasswordUI_Closed(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
private void OpenFile_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
|
|
@@ -42,7 +204,46 @@ namespace DigitalSignature
|
|
|
|
|
|
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
+ var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
|
|
|
+ if (item.Content as string == currentMode)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentMode == "Viewer")
|
|
|
+ {
|
|
|
+ regularViewerControl.ClearViewerControl();
|
|
|
+ regularViewerControl.IsActive = false;
|
|
|
+ }
|
|
|
+ else if(currentMode == "Digital Signature")
|
|
|
+ {
|
|
|
+ digitalSignatureControl.ClearViewerControl();
|
|
|
+ }
|
|
|
|
|
|
+ if (item.Content as string == "Viewer")
|
|
|
+ {
|
|
|
+ regularViewerControl.IsActive = true;
|
|
|
+ if (regularViewerControl.PdfViewControl != null && regularViewerControl.PdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ PDFGrid.Child = regularViewerControl;
|
|
|
+ regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
|
|
|
+ regularViewerControl.PdfViewControl = pdfViewer;
|
|
|
+ regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ regularViewerControl.SetBOTAContainer(botaBarControl);
|
|
|
+ regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (item.Content as string == "Digital Signature")
|
|
|
+ {
|
|
|
+ if (digitalSignatureControl.PdfViewControl != null && digitalSignatureControl.PdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ PDFGrid.Child = digitalSignatureControl;
|
|
|
+ digitalSignatureControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
|
|
|
+ digitalSignatureControl.PdfViewControl = pdfViewer;
|
|
|
+ digitalSignatureControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currentMode = item.Content as string;
|
|
|
}
|
|
|
|
|
|
private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
|
|
@@ -69,5 +270,16 @@ namespace DigitalSignature
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ pdfViewer = new PDFViewControl();
|
|
|
+ LoadDefaultDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Window_Unloaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|