DigitalSignatureControl.xaml.cs 25 KB

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