DigitalSignatureControl.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Controls.Primitives;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using Compdfkit_Tools.Helper;
  12. using ComPDFKit.DigitalSign;
  13. using ComPDFKit.PDFAnnotation.Form;
  14. using ComPDFKitViewer;
  15. namespace Compdfkit_Tools.PDFControl
  16. {
  17. public partial class DigitalSignatureControl : UserControl, INotifyPropertyChanged
  18. {
  19. #region Properties
  20. private bool isFirstLoad = true;
  21. public PDFViewControl PDFViewControl = new PDFViewControl();
  22. private SignatureStatusBarControl signatureStatusBarControl;
  23. private PanelState panelState = PanelState.GetInstance();
  24. private CPDFDisplaySettingsControl displaySettingsControl = null;
  25. private CPDFSignatureWidget currentSignatureWidget;
  26. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  27. public event EventHandler<bool> OnCanSaveChanged;
  28. public event EventHandler<string> AfterFillSignature;
  29. public event EventHandler SignatureStatusChanged;
  30. public event PropertyChangedEventHandler PropertyChanged;
  31. protected void OnPropertyChanged([CallerMemberName] string name = null)
  32. {
  33. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  34. }
  35. /// <summary>
  36. /// Whether the undo operation can be performed.
  37. /// </summary>
  38. public bool CanUndo
  39. {
  40. get
  41. {
  42. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  43. {
  44. return PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanUndo;
  45. }
  46. return false;
  47. }
  48. }
  49. /// <summary>
  50. /// Whether the redo operation can be performed.
  51. /// </summary>
  52. public bool CanRedo
  53. {
  54. get
  55. {
  56. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  57. {
  58. return PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanRedo;
  59. }
  60. return false;
  61. }
  62. }
  63. /// <summary>
  64. /// Whether the save operation can be performed.
  65. /// </summary>
  66. public bool CanSave
  67. {
  68. get
  69. {
  70. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  71. {
  72. if (PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanRedo ||
  73. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanUndo)
  74. {
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80. }
  81. #endregion
  82. /// <summary>
  83. /// A digital signature control should be used in a window, and it should be initialized with a PDFViewer.
  84. /// Certificates will be saved in the TrustedFolder.
  85. /// </summary>
  86. public DigitalSignatureControl()
  87. {
  88. InitializeComponent();
  89. DataContext = this;
  90. string trustedFolder = AppDomain.CurrentDomain.BaseDirectory + @"\TrustedFolder\";
  91. if (!Directory.Exists(trustedFolder))
  92. {
  93. Directory.CreateDirectory(trustedFolder);
  94. }
  95. CPDFSignature.SignCertTrustedFolder = trustedFolder;
  96. }
  97. #region Public Method
  98. /// <summary>
  99. /// Disconnect all the specified elements that are already the logical children of another element. And reset bar control status.
  100. /// </summary>
  101. public void ClearViewerControl()
  102. {
  103. PDFGrid.Child = null;
  104. BotaContainer.Child = null;
  105. PropertyContainer.Child = null;
  106. displaySettingsControl = null;
  107. SignatureStatusBorder.Child = null;
  108. DigitalSignatureBarControl.ClearAllToolState();
  109. }
  110. /// <summary>
  111. /// Init controls with pdfViewer, and load events.
  112. /// </summary>
  113. /// <param name="pdfViewer"></param>
  114. public void InitWithPDFViewer(PDFViewControl pdfViewer)
  115. {
  116. PDFViewControl = pdfViewer;
  117. PDFGrid.Child = PDFViewControl;
  118. FloatPageTool.InitWithPDFViewer(pdfViewer);
  119. PDFViewControl.PDFToolManager.SetToolType(ComPDFKit.Tool.CPDFToolManager.ToolType.Viewer);
  120. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.ClearHistory();
  121. DigitalSignatureBarControl.DigitalSignatureActionChanged -= DigitalSignatureBarControl_DigitalSignatureActionChanged;
  122. DigitalSignatureBarControl.DigitalSignatureActionChanged += DigitalSignatureBarControl_DigitalSignatureActionChanged;
  123. //PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
  124. //PDFViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
  125. //PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  126. //PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  127. panelState.PropertyChanged -= PanelState_PropertyChanged;
  128. panelState.PropertyChanged += PanelState_PropertyChanged;
  129. }
  130. /// <summary>
  131. /// Separately, init PDFView and load undo manager event. Only use for ensuring SaveBtn is enabled after deleting digital signature on Viewer mode.
  132. /// </summary>
  133. /// <param name="pdfViewer"></param>
  134. public void LoadUndoManagerEvent(CPDFViewer pdfViewer)
  135. {
  136. //PDFViewControl.PDFView = pdfViewer;
  137. //PDFViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  138. //PDFViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  139. }
  140. /// <summary>
  141. /// Set child for BOTAContainer with BOTABarControl.
  142. /// </summary>
  143. /// <param name="botaControl"></param>
  144. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  145. {
  146. BotaContainer.Child = botaControl;
  147. }
  148. /// <summary>
  149. /// Create a certificate info dialog with signature.
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e">Signature to init certificate</param>
  153. public void ViewCertificateEvent(object sender, CPDFSignature e)
  154. {
  155. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  156. ViewCertificateDialog dialog = new ViewCertificateDialog()
  157. {
  158. Owner = parentWindow
  159. };
  160. dialog.InitCertificateList(e);
  161. dialog.CertificateInfoControl.TrustCertificateEvent += (o, args) =>
  162. {
  163. SignatureStatusChanged?.Invoke(this, null);
  164. };
  165. if (parentWindow is VerifyDigitalSignatureControl verifyControl)
  166. {
  167. dialog.CertificateInfoControl.TrustCertificateEvent += (o, args) =>
  168. {
  169. verifyControl.InitWithSignature(e);
  170. };
  171. }
  172. dialog.ShowDialog();
  173. }
  174. /// <summary>
  175. /// Set display settings control.
  176. /// </summary>
  177. /// <param name="displaySettingsControl"></param>
  178. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  179. {
  180. this.displaySettingsControl = displaySettingsControl;
  181. }
  182. /// <summary>
  183. /// Set visibility of SignatureStatusBarControl according its status.
  184. /// </summary>
  185. /// <param name="signatureStatusBarControl"></param>
  186. public void SetSignatureStatusBarControl(SignatureStatusBarControl signatureStatusBarControl)
  187. {
  188. this.signatureStatusBarControl = signatureStatusBarControl;
  189. SignatureStatusBorder.Child = this.signatureStatusBarControl;
  190. if (signatureStatusBarControl.Status != SignatureStatus.None)
  191. {
  192. SignatureStatusBorder.Visibility = Visibility.Visible;
  193. }
  194. else
  195. {
  196. SignatureStatusBorder.Visibility = Visibility.Collapsed;
  197. }
  198. }
  199. /// <summary>
  200. /// Create a signature info dialog with signature.
  201. /// </summary>
  202. /// <param name="sender"></param>
  203. /// <param name="e">Signature to be displayed</param>
  204. public void ViewSignatureEvent(object sender, CPDFSignature e)
  205. {
  206. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  207. VerifyDigitalSignatureControl dialog = new VerifyDigitalSignatureControl()
  208. {
  209. Owner = parentWindow
  210. };
  211. dialog.ViewCertificateEvent -= ViewCertificateEvent;
  212. dialog.ViewCertificateEvent += ViewCertificateEvent;
  213. dialog.InitWithSignature(e);
  214. dialog.ShowDialog();
  215. }
  216. #endregion
  217. #region Private Method
  218. /// <summary>
  219. /// Get current time as a string.
  220. /// </summary>
  221. /// <returns></returns>
  222. private string GetTime()
  223. {
  224. DateTime dateTime = DateTime.Now;
  225. return " " + dateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
  226. }
  227. /// <summary>
  228. /// Create a signature field.
  229. /// </summary>
  230. private void CreateSign()
  231. {
  232. //PDFViewControl.PDFView.SetMouseMode(MouseModes.FormEditTool);
  233. //WidgetSignArgs signArgs = new WidgetSignArgs
  234. //{
  235. // LineWidth = 1,
  236. // LineColor = Colors.Black,
  237. // FieldName = "Signature" + GetTime()
  238. //};
  239. //PDFViewControl.PDFView.SetToolParam(signArgs);
  240. }
  241. /// <summary>
  242. /// Expand or collapse left panel.
  243. /// </summary>
  244. /// <param name="isExpand"></param>
  245. private void ExpandLeftPanel(bool isExpand)
  246. {
  247. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  248. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  249. if (isExpand)
  250. {
  251. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  252. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  253. }
  254. else
  255. {
  256. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  257. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  258. }
  259. }
  260. /// <summary>
  261. /// Expand or collapse right panel.
  262. /// </summary>
  263. /// <param name="propertytPanel"></param>
  264. /// <param name="visible"></param>
  265. private void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  266. {
  267. PropertyContainer.Width = 260;
  268. PropertyContainer.Child = propertytPanel;
  269. PropertyContainer.Visibility = visible;
  270. }
  271. #endregion
  272. #region Private Command Event
  273. /// <summary>
  274. /// Click event of signature field.
  275. /// </summary>
  276. /// <param name="sender"></param>
  277. /// <param name="e"></param>
  278. //private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
  279. //{
  280. // var signatureWidget = (e as WidgetSignArgs).Sign;
  281. // CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.PDFView.Document);
  282. // if (signatureWidget.IsSigned() && sig!=null && sig?.SignerList.Count > 0)
  283. // {
  284. // ViewSignatureEvent(sender, sig);
  285. // }
  286. // else
  287. // {
  288. // Window parentWindow = Window.GetWindow((DependencyObject)sender);
  289. // AddCertificationDialog addCertificationControl = new AddCertificationDialog
  290. // {
  291. // Owner = parentWindow
  292. // };
  293. // currentSignatureWidget = signatureWidget;
  294. // addCertificationControl.FillSignatureEvent -= AddCertificationControl_FillSignatureEvent;
  295. // addCertificationControl.FillSignatureEvent += AddCertificationControl_FillSignatureEvent;
  296. // addCertificationControl.ShowDialog();
  297. // }
  298. //}
  299. /// <summary>
  300. /// Event of filling a signature.
  301. /// </summary>
  302. /// <param name="sender"></param>
  303. /// <param name="e"></param>
  304. private void AddCertificationControl_FillSignatureEvent(object sender, CertificateAccess e)
  305. {
  306. FillDigitalSignatureDialog fillDigitalSignatureDialog = new FillDigitalSignatureDialog
  307. {
  308. FilePath = e.filePath,
  309. Password = e.password,
  310. SignatureWidget = currentSignatureWidget,
  311. //Document = PDFViewControl.PDFView.Document,
  312. Owner = Window.GetWindow(this)
  313. };
  314. fillDigitalSignatureDialog.AfterFillSignature -= FillDigitalSignatureDialog_AfterFillSignature; ;
  315. fillDigitalSignatureDialog.AfterFillSignature += FillDigitalSignatureDialog_AfterFillSignature; ;
  316. fillDigitalSignatureDialog.ShowDialog();
  317. }
  318. /// <summary>
  319. /// Event of after filling a signature.
  320. /// </summary>
  321. /// <param name="sender"></param>
  322. /// <param name="e"></param>
  323. private void FillDigitalSignatureDialog_AfterFillSignature(object sender, string e)
  324. {
  325. AfterFillSignature?.Invoke(this, e);
  326. }
  327. /// <summary>
  328. /// Click event of buttons in digital SignatureBarControl.
  329. /// </summary>
  330. /// <param name="sender"></param>
  331. /// <param name="e"></param>
  332. private void DigitalSignatureBarControl_DigitalSignatureActionChanged(object sender, Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction e)
  333. {
  334. if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.AddSignatureField)
  335. {
  336. CreateSign();
  337. }
  338. else if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.Signing)
  339. {
  340. PDFViewControl.PDFToolManager.SetToolType(ComPDFKit.Tool.CPDFToolManager.ToolType.Viewer);
  341. }
  342. else if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.VerifySignature)
  343. {
  344. ToggleButton button = sender as ToggleButton;
  345. button.IsChecked = false;
  346. SignatureStatusChanged?.Invoke(this, null);
  347. }
  348. }
  349. /// <summary>
  350. /// Property changed event of PanelState.
  351. /// </summary>
  352. /// <param name="sender"></param>
  353. /// <param name="e"></param>
  354. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  355. {
  356. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  357. {
  358. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  359. }
  360. else if (e.PropertyName == nameof(PanelState.RightPanel))
  361. {
  362. if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  363. {
  364. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  365. }
  366. else
  367. {
  368. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  369. }
  370. }
  371. }
  372. /// <summary>
  373. /// Event of UndoManager property changed.
  374. /// </summary>
  375. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  376. {
  377. OnPropertyChanged(e.PropertyName);
  378. if (e.PropertyName == "CanSave")
  379. {
  380. OnCanSaveChanged?.Invoke(this, CanSave);
  381. }
  382. }
  383. /// <summary>
  384. /// Command event of undo operation.
  385. /// </summary>
  386. /// <param name="sender"></param>
  387. /// <param name="e"></param>
  388. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  389. {
  390. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  391. {
  392. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  393. }
  394. }
  395. /// <summary>
  396. /// Command event of redo operation.
  397. /// </summary>
  398. /// <param name="sender"></param>
  399. /// <param name="e"></param>
  400. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  401. {
  402. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  403. {
  404. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  405. }
  406. }
  407. /// <summary>
  408. /// Click event of undo button.
  409. /// </summary>
  410. /// <param name="sender"></param>
  411. /// <param name="e"></param>
  412. private void UndoButton_Click(object sender, RoutedEventArgs e)
  413. {
  414. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  415. {
  416. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  417. }
  418. }
  419. /// <summary>
  420. /// Click event of redo button.
  421. /// </summary>
  422. /// <param name="sender"></param>
  423. /// <param name="e"></param>
  424. private void RedoButton_Click(object sender, RoutedEventArgs e)
  425. {
  426. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanRedo)
  427. {
  428. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  429. }
  430. }
  431. #endregion
  432. #region ContextMenu
  433. /// <summary>
  434. /// Right click context menu
  435. /// </summary>
  436. /// <param name="sender"></param>
  437. /// <param name="e"></param>
  438. //private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  439. //{
  440. // if (e != null && e.CommandType == CommandType.Context)
  441. // {
  442. // if (e.CommandTarget == TargetType.WidgetView)
  443. // {
  444. // e.Handle = true;
  445. // e.PopupMenu = new ContextMenu();
  446. // var sign = e.Sign.GetSignature(PDFViewControl.PDFView.Document);
  447. // if (e.Sign.IsSigned() && sign != null && sign.SignerList.Any())
  448. // {
  449. // MenuItem DeleteMenu = new MenuItem()
  450. // { Header = LanguageHelper.CommonManager.GetString("Menu_Delete") };
  451. // DeleteMenu.Click += (o, args) =>
  452. // {
  453. // PDFViewControl.PDFView.Document.RemoveSignature(sign, true);
  454. // e.Sign.ResetForm();
  455. // e.Sign.SetIsLocked(false);
  456. // PDFViewControl.PDFView.ReloadVisibleAnnots();
  457. // PDFViewControl.PDFView.UndoManager.CanSave = true;
  458. // SignatureStatusChanged?.Invoke(this, null);
  459. // };
  460. // e.PopupMenu.Items.Add(DeleteMenu);
  461. // }
  462. // else
  463. // {
  464. // e.PopupMenu.Items.Add(new MenuItem()
  465. // { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  466. // e.PopupMenu.Items.Add(new MenuItem()
  467. // { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  468. // e.PopupMenu.Items.Add(new MenuItem()
  469. // { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  470. // }
  471. // }
  472. // else if (e.PressOnSelectedText)
  473. // {
  474. // e.Handle = true;
  475. // e.PopupMenu = new ContextMenu();
  476. // e.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  477. // }
  478. // else
  479. // {
  480. // e.Handle = true;
  481. // e.PopupMenu = new ContextMenu();
  482. // e.PopupMenu.Items.Add(new MenuItem()
  483. // { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  484. // e.PopupMenu.Items.Add(new Separator());
  485. // MenuItem fitWidthMenu = new MenuItem();
  486. // fitWidthMenu.Header = LanguageHelper.CommonManager.GetString("Menu_AutoSize");
  487. // fitWidthMenu.Click += (o, p) =>
  488. // {
  489. // if (PDFViewControl != null)
  490. // {
  491. // PDFViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  492. // }
  493. // };
  494. // e.PopupMenu.Items.Add(fitWidthMenu);
  495. // MenuItem fitSizeMenu = new MenuItem();
  496. // fitSizeMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RealSize");
  497. // fitSizeMenu.Click += (o, p) =>
  498. // {
  499. // if (PDFViewControl != null)
  500. // {
  501. // PDFViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  502. // }
  503. // };
  504. // e.PopupMenu.Items.Add(fitSizeMenu);
  505. // MenuItem zoomInMenu = new MenuItem();
  506. // zoomInMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomIn");
  507. // zoomInMenu.Click += (o, p) =>
  508. // {
  509. // if (PDFViewControl != null)
  510. // {
  511. // double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,
  512. // PDFViewControl.PDFView.ZoomFactor + 0.01, true);
  513. // PDFViewControl.PDFView?.Zoom(newZoom);
  514. // }
  515. // };
  516. // e.PopupMenu.Items.Add(zoomInMenu);
  517. // MenuItem zoomOutMenu = new MenuItem();
  518. // zoomOutMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomOut");
  519. // zoomOutMenu.Click += (o, p) =>
  520. // {
  521. // if (PDFViewControl != null)
  522. // {
  523. // double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,
  524. // PDFViewControl.PDFView.ZoomFactor - 0.01, false);
  525. // PDFViewControl.PDFView?.Zoom(newZoom);
  526. // }
  527. // };
  528. // e.PopupMenu.Items.Add(zoomOutMenu);
  529. // e.PopupMenu.Items.Add(new Separator());
  530. // MenuItem singleView = new MenuItem();
  531. // singleView.Header = LanguageHelper.CommonManager.GetString("Menu_SinglePage");
  532. // singleView.Click += (o, p) =>
  533. // {
  534. // if (PDFViewControl != null)
  535. // {
  536. // PDFViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  537. // }
  538. // };
  539. // e.PopupMenu.Items.Add(singleView);
  540. // MenuItem singleContinuousView = new MenuItem();
  541. // singleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_SingleContinuous");
  542. // singleContinuousView.Click += (o, p) =>
  543. // {
  544. // if (PDFViewControl != null)
  545. // {
  546. // PDFViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  547. // }
  548. // };
  549. // e.PopupMenu.Items.Add(singleContinuousView);
  550. // MenuItem doubleView = new MenuItem();
  551. // doubleView.Header = LanguageHelper.CommonManager.GetString("Menu_DoublePage");
  552. // doubleView.Click += (o, p) =>
  553. // {
  554. // if (PDFViewControl != null)
  555. // {
  556. // PDFViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  557. // }
  558. // };
  559. // e.PopupMenu.Items.Add(doubleView);
  560. // MenuItem doubleContinuousView = new MenuItem();
  561. // doubleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_DoubleContinuous");
  562. // doubleContinuousView.Click += (o, p) =>
  563. // {
  564. // if (PDFViewControl != null)
  565. // {
  566. // PDFViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  567. // }
  568. // };
  569. // e.PopupMenu.Items.Add(doubleContinuousView);
  570. // MenuItem resetFormMenu = new MenuItem();
  571. // resetFormMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Reset");
  572. // resetFormMenu.Click += (o, p) =>
  573. // {
  574. // if (PDFViewControl != null)
  575. // {
  576. // PDFViewControl.PDFView?.ResetForm(null);
  577. // }
  578. // };
  579. // e.PopupMenu.Items.Add(new Separator());
  580. // e.PopupMenu.Items.Add(resetFormMenu);
  581. // }
  582. // }
  583. // if (e != null && e.CommandType == CommandType.Copy)
  584. // {
  585. // if (PDFViewControl?.PDFView == null) return;
  586. // if (!PDFViewControl.PDFView.Document.GetPermissionsInfo().AllowsCopying)
  587. // {
  588. // if(!PasswordHelper.UnlockWithOwnerPassword(PDFViewControl.PDFView.Document))
  589. // {
  590. // return;
  591. // }
  592. // }
  593. // }
  594. // e?.DoCommand();
  595. //}
  596. #endregion
  597. #region Load Unload Event
  598. /// <summary>
  599. /// Load event
  600. /// </summary>
  601. /// <param name="sender"></param>
  602. /// <param name="e"></param>
  603. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  604. {
  605. }
  606. /// <summary>
  607. /// Unload event
  608. /// </summary>
  609. /// <param name="sender"></param>
  610. /// <param name="e"></param>
  611. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  612. {
  613. //PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  614. //PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
  615. }
  616. #endregion
  617. }
  618. }