DigitalSignatureControl.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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.WidgetEdit && e.annotType== C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  196. {
  197. BaseWidget baseWidget = PDFViewControl.GetCacheHitTestWidget();
  198. if(baseWidget == null)
  199. {
  200. return;
  201. }
  202. var widget = baseWidget.GetAnnotData().Annot as CPDFWidget;
  203. if (widget == null)
  204. {
  205. return;
  206. }
  207. if (widget.WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
  208. {
  209. var signatureWidget = widget as CPDFSignatureWidget;
  210. CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.GetCPDFViewer().GetDocument());
  211. if (signatureWidget.IsSigned() && sig != null && sig?.SignerList.Count > 0)
  212. {
  213. ViewSignatureEvent(sender, sig);
  214. }
  215. else
  216. {
  217. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  218. AddCertificationDialog addCertificationControl = new AddCertificationDialog
  219. {
  220. Owner = parentWindow
  221. };
  222. currentSignatureWidget = signatureWidget;
  223. addCertificationControl.FillSignatureEvent -= AddCertificationControl_FillSignatureEvent;
  224. addCertificationControl.FillSignatureEvent += AddCertificationControl_FillSignatureEvent;
  225. addCertificationControl.ShowDialog();
  226. }
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// Set child for BOTAContainer with BOTABarControl.
  232. /// </summary>
  233. /// <param name="botaControl"></param>
  234. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  235. {
  236. BotaContainer.Child = botaControl;
  237. }
  238. /// <summary>
  239. /// Create a certificate info dialog with signature.
  240. /// </summary>
  241. /// <param name="sender"></param>
  242. /// <param name="e">Signature to init certificate</param>
  243. public void ViewCertificateEvent(object sender, CPDFSignature e)
  244. {
  245. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  246. ViewCertificateDialog dialog = new ViewCertificateDialog()
  247. {
  248. Owner = parentWindow
  249. };
  250. dialog.InitCertificateList(e);
  251. dialog.CertificateInfoControl.TrustCertificateEvent += (o, args) =>
  252. {
  253. SignatureStatusChanged?.Invoke(this, null);
  254. };
  255. if (parentWindow is VerifyDigitalSignatureControl verifyControl)
  256. {
  257. dialog.CertificateInfoControl.TrustCertificateEvent += (o, args) =>
  258. {
  259. verifyControl.InitWithSignature(e);
  260. };
  261. }
  262. dialog.ShowDialog();
  263. }
  264. /// <summary>
  265. /// Set display settings control.
  266. /// </summary>
  267. /// <param name="displaySettingsControl"></param>
  268. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  269. {
  270. this.displaySettingsControl = displaySettingsControl;
  271. }
  272. /// <summary>
  273. /// Set visibility of SignatureStatusBarControl according its status.
  274. /// </summary>
  275. /// <param name="signatureStatusBarControl"></param>
  276. public void SetSignatureStatusBarControl(SignatureStatusBarControl signatureStatusBarControl)
  277. {
  278. this.signatureStatusBarControl = signatureStatusBarControl;
  279. SignatureStatusBorder.Child = this.signatureStatusBarControl;
  280. if (signatureStatusBarControl.Status != SignatureStatus.None)
  281. {
  282. SignatureStatusBorder.Visibility = Visibility.Visible;
  283. }
  284. else
  285. {
  286. SignatureStatusBorder.Visibility = Visibility.Collapsed;
  287. }
  288. }
  289. /// <summary>
  290. /// Create a signature info dialog with signature.
  291. /// </summary>
  292. /// <param name="sender"></param>
  293. /// <param name="e">Signature to be displayed</param>
  294. public void ViewSignatureEvent(object sender, CPDFSignature e)
  295. {
  296. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  297. VerifyDigitalSignatureControl dialog = new VerifyDigitalSignatureControl()
  298. {
  299. Owner = parentWindow
  300. };
  301. dialog.ViewCertificateEvent -= ViewCertificateEvent;
  302. dialog.ViewCertificateEvent += ViewCertificateEvent;
  303. dialog.InitWithSignature(e);
  304. dialog.ShowDialog();
  305. }
  306. public void UnloadEvent()
  307. {
  308. PDFViewControl.PDFViewTool.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
  309. PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler -= PDFViewControl_MouseLeftButtonDownHandler;
  310. DigitalSignatureBarControl.DigitalSignatureActionChanged -= DigitalSignatureBarControl_DigitalSignatureActionChanged;
  311. panelState.PropertyChanged -= PanelState_PropertyChanged;
  312. }
  313. #endregion
  314. #region Private Method
  315. /// <summary>
  316. /// Get current time as a string.
  317. /// </summary>
  318. /// <returns></returns>
  319. private string GetTime()
  320. {
  321. DateTime dateTime = DateTime.Now;
  322. return " " + dateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
  323. }
  324. /// <summary>
  325. /// Create a signature field.
  326. /// </summary>
  327. private void CreateSign()
  328. {
  329. PDFViewControl.PDFToolManager.SetToolType(ToolType.WidgetEdit);
  330. PDFViewControl.SetCreateWidgetType(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS);
  331. SignatureParam signatureParam = new SignatureParam
  332. {
  333. FieldName = "Signature" + GetTime(),
  334. CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET,
  335. WidgetType = C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS,
  336. LineWidth = 1,
  337. FontName = "Helvetica",
  338. LineColor =new byte[] {0,0,0 },
  339. FontColor = new byte[] { 0, 0, 0 },
  340. Transparency = 255,
  341. HasLineColor = true,
  342. };
  343. PDFViewControl.SetAnnotParam(signatureParam);
  344. }
  345. /// <summary>
  346. /// Expand or collapse left panel.
  347. /// </summary>
  348. /// <param name="isExpand"></param>
  349. private void ExpandLeftPanel(bool isExpand)
  350. {
  351. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  352. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  353. if (isExpand)
  354. {
  355. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  356. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  357. }
  358. else
  359. {
  360. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  361. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  362. }
  363. }
  364. /// <summary>
  365. /// Expand or collapse right panel.
  366. /// </summary>
  367. /// <param name="propertytPanel"></param>
  368. /// <param name="visible"></param>
  369. private void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  370. {
  371. PropertyContainer.Width = 260;
  372. PropertyContainer.Child = propertytPanel;
  373. PropertyContainer.Visibility = visible;
  374. }
  375. #endregion
  376. #region Private Command Event
  377. /// <summary>
  378. /// Click event of signature field.
  379. /// </summary>
  380. /// <param name="sender"></param>
  381. /// <param name="e"></param>
  382. //private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
  383. //{
  384. // var signatureWidget = (e as WidgetSignArgs).Sign;
  385. // CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.PDFView.Document);
  386. // if (signatureWidget.IsSigned() && sig!=null && sig?.SignerList.Count > 0)
  387. // {
  388. // ViewSignatureEvent(sender, sig);
  389. // }
  390. // else
  391. // {
  392. // Window parentWindow = Window.GetWindow((DependencyObject)sender);
  393. // AddCertificationDialog addCertificationControl = new AddCertificationDialog
  394. // {
  395. // Owner = parentWindow
  396. // };
  397. // currentSignatureWidget = signatureWidget;
  398. // addCertificationControl.FillSignatureEvent -= AddCertificationControl_FillSignatureEvent;
  399. // addCertificationControl.FillSignatureEvent += AddCertificationControl_FillSignatureEvent;
  400. // addCertificationControl.ShowDialog();
  401. // }
  402. //}
  403. /// <summary>
  404. /// Event of filling a signature.
  405. /// </summary>
  406. /// <param name="sender"></param>
  407. /// <param name="e"></param>
  408. private void AddCertificationControl_FillSignatureEvent(object sender, CertificateAccess e)
  409. {
  410. FillDigitalSignatureDialog fillDigitalSignatureDialog = new FillDigitalSignatureDialog
  411. {
  412. FilePath = e.filePath,
  413. Password = e.password,
  414. SignatureWidget = currentSignatureWidget,
  415. Document = PDFViewControl.GetCPDFViewer().GetDocument(),
  416. Owner = Window.GetWindow(this)
  417. };
  418. fillDigitalSignatureDialog.AfterFillSignature -= FillDigitalSignatureDialog_AfterFillSignature; ;
  419. fillDigitalSignatureDialog.AfterFillSignature += FillDigitalSignatureDialog_AfterFillSignature; ;
  420. fillDigitalSignatureDialog.ShowDialog();
  421. }
  422. /// <summary>
  423. /// Event of after filling a signature.
  424. /// </summary>
  425. /// <param name="sender"></param>
  426. /// <param name="e"></param>
  427. private void FillDigitalSignatureDialog_AfterFillSignature(object sender, string e)
  428. {
  429. AfterFillSignature?.Invoke(this, e);
  430. }
  431. /// <summary>
  432. /// Click event of buttons in digital SignatureBarControl.
  433. /// </summary>
  434. /// <param name="sender"></param>
  435. /// <param name="e"></param>
  436. private void DigitalSignatureBarControl_DigitalSignatureActionChanged(object sender, Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction e)
  437. {
  438. if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.AddSignatureField)
  439. {
  440. CreateSign();
  441. }
  442. else if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.Signing)
  443. {
  444. PDFViewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  445. }
  446. else if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.VerifySignature)
  447. {
  448. ToggleButton button = sender as ToggleButton;
  449. button.IsChecked = false;
  450. SignatureStatusChanged?.Invoke(this, null);
  451. }
  452. }
  453. /// <summary>
  454. /// Property changed event of PanelState.
  455. /// </summary>
  456. /// <param name="sender"></param>
  457. /// <param name="e"></param>
  458. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  459. {
  460. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  461. {
  462. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  463. }
  464. else if (e.PropertyName == nameof(PanelState.RightPanel))
  465. {
  466. if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  467. {
  468. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  469. }
  470. else
  471. {
  472. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  473. }
  474. }
  475. }
  476. /// <summary>
  477. /// Event of UndoManager property changed.
  478. /// </summary>
  479. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  480. {
  481. OnPropertyChanged(e.PropertyName);
  482. if (e.PropertyName == "CanSave")
  483. {
  484. OnCanSaveChanged?.Invoke(this, CanSave);
  485. }
  486. }
  487. /// <summary>
  488. /// Command event of undo operation.
  489. /// </summary>
  490. /// <param name="sender"></param>
  491. /// <param name="e"></param>
  492. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  493. {
  494. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  495. {
  496. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  497. }
  498. }
  499. /// <summary>
  500. /// Command event of redo operation.
  501. /// </summary>
  502. /// <param name="sender"></param>
  503. /// <param name="e"></param>
  504. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  505. {
  506. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  507. {
  508. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  509. }
  510. }
  511. /// <summary>
  512. /// Click event of undo button.
  513. /// </summary>
  514. /// <param name="sender"></param>
  515. /// <param name="e"></param>
  516. private void UndoButton_Click(object sender, RoutedEventArgs e)
  517. {
  518. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  519. {
  520. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  521. }
  522. }
  523. /// <summary>
  524. /// Click event of redo button.
  525. /// </summary>
  526. /// <param name="sender"></param>
  527. /// <param name="e"></param>
  528. private void RedoButton_Click(object sender, RoutedEventArgs e)
  529. {
  530. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanRedo)
  531. {
  532. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  533. }
  534. }
  535. #endregion
  536. #region ContextMenu
  537. /// <summary>
  538. /// Right click context menu
  539. /// </summary>
  540. /// <param name="sender"></param>
  541. /// <param name="e"></param>
  542. private void PDFView_AnnotCommandHandler(object sender, MouseEventObject e)
  543. {
  544. ContextMenu ContextMenu = PDFViewControl.GetRightMenu();
  545. if (ContextMenu == null)
  546. {
  547. ContextMenu = new ContextMenu();
  548. }
  549. switch (e.hitTestType)
  550. {
  551. case MouseHitTestType.Annot:
  552. case MouseHitTestType.SelectRect:
  553. break;
  554. case MouseHitTestType.Text:
  555. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  556. break;
  557. default:
  558. PDFViewControl.CreateViewerMenu(sender, ref ContextMenu);
  559. break;
  560. }
  561. PDFViewControl.SetRightMenu(ContextMenu);
  562. }
  563. #endregion
  564. }
  565. }