AnnotationControl.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. using System.Windows.Controls;
  2. using Compdfkit_Tools.Data;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Win32;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Runtime.CompilerServices;
  14. using System.Windows;
  15. using System.Windows.Controls.Primitives;
  16. using System.Windows.Input;
  17. using System.Windows.Media.Imaging;
  18. namespace Compdfkit_Tools.PDFControl
  19. {
  20. public partial class AnnotationControl : UserControl, INotifyPropertyChanged
  21. {
  22. #region Property
  23. private bool isFirstLoad = true;
  24. public PDFViewControl PdfViewControl;
  25. public CPDFAnnotationControl PDFAnnotationControl = null;
  26. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  27. public event PropertyChangedEventHandler PropertyChanged;
  28. public ICommand CloseTabCommand;
  29. public ICommand ExpandPropertyPanelCommand;
  30. public bool CanUndo
  31. {
  32. get
  33. {
  34. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  35. {
  36. return PdfViewControl.PDFView.UndoManager.CanUndo;
  37. }
  38. return false;
  39. }
  40. }
  41. public bool CanRedo
  42. {
  43. get
  44. {
  45. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  46. {
  47. return PdfViewControl.PDFView.UndoManager.CanRedo;
  48. }
  49. return false;
  50. }
  51. }
  52. private bool CanSave
  53. {
  54. get
  55. {
  56. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  57. {
  58. return PdfViewControl.PDFView.UndoManager.CanSave;
  59. }
  60. return false;
  61. }
  62. }
  63. public event EventHandler<bool> OnCanSaveChanged;
  64. public event EventHandler OnAnnotEditHandler;
  65. #endregion
  66. public AnnotationControl()
  67. {
  68. InitializeComponent();
  69. DataContext = this;
  70. PDFAnnotationControl = new CPDFAnnotationControl();
  71. CPDFAnnotationType[] annotationProperties =
  72. {
  73. CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout,
  74. CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText,
  75. CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square,
  76. CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Image,
  77. CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link,
  78. CPDFAnnotationType.Audio
  79. };
  80. AnnotationBarControl.InitAnnotationBar(annotationProperties);
  81. }
  82. #region Init PDFViewer
  83. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  84. {
  85. PdfViewControl.PDFView = pdfViewer;
  86. PDFGrid.Child = PdfViewControl;
  87. FloatPageTool.InitWithPDFViewer(pdfViewer);
  88. DataContext = this;
  89. }
  90. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  91. {
  92. this.BotaContainer.Child = botaControl;
  93. }
  94. public void ClearAllToolState()
  95. {
  96. this.AnnotationBarControl.ClearAllToolState();
  97. }
  98. public void SetToolBarContainerVisibility(Visibility visibility)
  99. {
  100. this.ToolBarContainer.Visibility = visibility;
  101. }
  102. #endregion
  103. #region Load Unload custom control
  104. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  105. {
  106. InitialPDFViewControl(PdfViewControl);
  107. }
  108. private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
  109. {
  110. AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
  111. AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
  112. }
  113. private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
  114. {
  115. AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
  116. AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
  117. }
  118. #endregion
  119. #region Annotation
  120. public void InitialPDFViewControl(PDFViewControl newPDFViewer)
  121. {
  122. PDFAnnotationControl.SetPDFViewer(newPDFViewer.PDFView);
  123. PDFAnnotationControl.AnnotationCancel();
  124. AnnotationBarControl.ClearAllToolState();
  125. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  126. PDFAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  127. PDFAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
  128. PdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  129. PdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  130. PdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
  131. PdfViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
  132. PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  133. PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  134. PdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
  135. PdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
  136. }
  137. public void UnloadEvent()
  138. {
  139. PdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
  140. PdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
  141. }
  142. private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
  143. {
  144. AnnotationBarControl.ClearAllToolState();
  145. }
  146. public void SetViewSettings(Visibility visibility ,CPDFDisplaySettingsControl displaySettingsControl = null)
  147. {
  148. this.PropertyContainer.Child = displaySettingsControl;
  149. this.PropertyContainer.Visibility = visibility;
  150. }
  151. #endregion
  152. #region Expand and collapse Panel
  153. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  154. {
  155. PropertyContainer.Width = 260;
  156. PropertyContainer.Child = propertytPanel;
  157. PropertyContainer.Visibility = visible;
  158. }
  159. public void ExpandLeftPanel(bool isExpand)
  160. {
  161. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  162. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  163. if (isExpand)
  164. {
  165. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  166. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  167. }
  168. else
  169. {
  170. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  171. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  172. }
  173. }
  174. #endregion
  175. #region Context menu
  176. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  177. {
  178. switch (e.CommandType)
  179. {
  180. case CommandType.Context:
  181. e.Handle = true;
  182. if (e.CommandTarget == TargetType.Annot)
  183. {
  184. e.Handle = true;
  185. e.PopupMenu = new ContextMenu();
  186. if (e.PressOnLink && AnnotationBarControl.CurrentMode == "Link")
  187. {
  188. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  189. MenuItem propertyMenu = new MenuItem();
  190. propertyMenu = new MenuItem();
  191. propertyMenu.Header = "Edit";
  192. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(propertyMenu, "Click", EditLink_Click);
  193. propertyMenu.CommandParameter = e;
  194. e.PopupMenu.Items.Add(propertyMenu);
  195. }
  196. else if (e.PressOnAnnot)
  197. {
  198. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  199. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  200. e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  201. }
  202. else if (e.PressOnMedia || e.PressOnSound)
  203. {
  204. e.Handle = true;
  205. e.PopupMenu.Items.Add(new MenuItem() { Header = "Play", Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = e });
  206. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  207. }
  208. else if (e.PressOnSelectedText)
  209. {
  210. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  211. MenuItem highLightMenu = new MenuItem();
  212. highLightMenu.Header = "HighLight";
  213. highLightMenu.Click += (o, p) =>
  214. {
  215. TextHighlightAnnotArgs highLightArgs = new TextHighlightAnnotArgs();
  216. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  217. if (PDFAnnotationControl != null)
  218. {
  219. highLightArgs.Color = System.Windows.Media.Colors.Red;
  220. highLightArgs.Transparency = 1;
  221. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  222. PdfViewControl.PDFView.SetToolParam(highLightArgs);
  223. PdfViewControl.PDFView.SetMouseMode(oldMode);
  224. }
  225. };
  226. e.PopupMenu.Items.Add(highLightMenu);
  227. MenuItem underlineMenu = new MenuItem();
  228. underlineMenu.Header = "UnderLine";
  229. underlineMenu.Click += (o, p) =>
  230. {
  231. TextUnderlineAnnotArgs underlineArgs = new TextUnderlineAnnotArgs();
  232. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  233. if (PDFAnnotationControl != null)
  234. {
  235. underlineArgs.Color = System.Windows.Media.Colors.Red;
  236. underlineArgs.Transparency = 1;
  237. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  238. PdfViewControl.PDFView.SetToolParam(underlineArgs);
  239. PdfViewControl.PDFView.SetMouseMode(oldMode);
  240. }
  241. };
  242. e.PopupMenu.Items.Add(underlineMenu);
  243. MenuItem strikeOutMenu = new MenuItem();
  244. strikeOutMenu.Header = "StrikeOut";
  245. strikeOutMenu.Click += (o, p) =>
  246. {
  247. TextStrikeoutAnnotArgs strikeoutAnnotArgs = new TextStrikeoutAnnotArgs();
  248. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  249. if (PDFAnnotationControl != null)
  250. {
  251. strikeoutAnnotArgs.Color = System.Windows.Media.Colors.Red;
  252. strikeoutAnnotArgs.Transparency = 1;
  253. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  254. PdfViewControl.PDFView.SetToolParam(strikeoutAnnotArgs);
  255. PdfViewControl.PDFView.SetMouseMode(oldMode);
  256. }
  257. };
  258. e.PopupMenu.Items.Add(strikeOutMenu);
  259. MenuItem SquiggleMenu = new MenuItem();
  260. SquiggleMenu.Header = "Squiggle";
  261. SquiggleMenu.Click += (o, p) =>
  262. {
  263. TextSquigglyAnnotArgs squigglyAnnotArgs = new TextSquigglyAnnotArgs();
  264. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  265. if (PDFAnnotationControl != null)
  266. {
  267. squigglyAnnotArgs.Color = System.Windows.Media.Colors.Red;
  268. squigglyAnnotArgs.Transparency = 1;
  269. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  270. PdfViewControl.PDFView.SetToolParam(squigglyAnnotArgs);
  271. PdfViewControl.PDFView.SetMouseMode(oldMode);
  272. }
  273. };
  274. e.PopupMenu.Items.Add(SquiggleMenu);
  275. }
  276. else
  277. {
  278. e.Handle = true;
  279. e.PopupMenu = new ContextMenu();
  280. e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  281. e.PopupMenu.Items.Add(new Separator());
  282. MenuItem fitWidthMenu = new MenuItem();
  283. fitWidthMenu.Header = "Automatically Resize";
  284. fitWidthMenu.Click += (o, p) =>
  285. {
  286. if (PdfViewControl != null)
  287. {
  288. PdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  289. }
  290. };
  291. e.PopupMenu.Items.Add(fitWidthMenu);
  292. MenuItem fitSizeMenu = new MenuItem();
  293. fitSizeMenu.Header = "Actual Size";
  294. fitSizeMenu.Click += (o, p) =>
  295. {
  296. if (PdfViewControl != null)
  297. {
  298. PdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  299. }
  300. };
  301. e.PopupMenu.Items.Add(fitSizeMenu);
  302. MenuItem zoomInMenu = new MenuItem();
  303. zoomInMenu.Header = "Zoom In";
  304. zoomInMenu.Click += (o, p) =>
  305. {
  306. if (PdfViewControl != null)
  307. {
  308. double newZoom = CheckZoomLevel(PdfViewControl.PDFView.ZoomFactor + 0.01, true);
  309. PdfViewControl.PDFView?.Zoom(newZoom);
  310. }
  311. };
  312. e.PopupMenu.Items.Add(zoomInMenu);
  313. MenuItem zoomOutMenu = new MenuItem();
  314. zoomOutMenu.Header = "Zoom Out";
  315. zoomOutMenu.Click += (o, p) =>
  316. {
  317. if (PdfViewControl != null)
  318. {
  319. double newZoom = CheckZoomLevel(PdfViewControl.PDFView.ZoomFactor - 0.01, false);
  320. PdfViewControl.PDFView?.Zoom(newZoom);
  321. }
  322. };
  323. e.PopupMenu.Items.Add(zoomOutMenu);
  324. e.PopupMenu.Items.Add(new Separator());
  325. MenuItem singleView = new MenuItem();
  326. singleView.Header = "Single Page";
  327. singleView.Click += (o, p) =>
  328. {
  329. if (PdfViewControl != null)
  330. {
  331. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  332. }
  333. };
  334. e.PopupMenu.Items.Add(singleView);
  335. MenuItem singleContinuousView = new MenuItem();
  336. singleContinuousView.Header = "Single Page Continuous";
  337. singleContinuousView.Click += (o, p) =>
  338. {
  339. if (PdfViewControl != null)
  340. {
  341. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  342. }
  343. };
  344. e.PopupMenu.Items.Add(singleContinuousView);
  345. MenuItem doubleView = new MenuItem();
  346. doubleView.Header = "Two Pages";
  347. doubleView.Click += (o, p) =>
  348. {
  349. if (PdfViewControl != null)
  350. {
  351. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  352. }
  353. };
  354. e.PopupMenu.Items.Add(doubleView);
  355. MenuItem doubleContinuousView = new MenuItem();
  356. doubleContinuousView.Header = "Two Pages Continuous";
  357. doubleContinuousView.Click += (o, p) =>
  358. {
  359. if (PdfViewControl != null)
  360. {
  361. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  362. }
  363. };
  364. e.PopupMenu.Items.Add(doubleContinuousView);
  365. }
  366. }
  367. else if (e.CommandTarget == TargetType.ImageSelection)
  368. {
  369. if (PdfViewControl != null && PdfViewControl.PDFView != null && PdfViewControl.PDFView.GetSelectImageCount() > 0)
  370. {
  371. e.Handle = true;
  372. e.PopupMenu = new ContextMenu();
  373. MenuItem imageCopyMenu = new MenuItem();
  374. imageCopyMenu = new MenuItem();
  375. imageCopyMenu.Header = "Copy Images";
  376. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  377. imageCopyMenu.CommandParameter = e;
  378. e.PopupMenu.Items.Add(imageCopyMenu);
  379. MenuItem imageExtraMenu = new MenuItem();
  380. imageExtraMenu = new MenuItem();
  381. imageExtraMenu.Header = "Extract Images";
  382. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  383. imageExtraMenu.CommandParameter = e;
  384. e.PopupMenu.Items.Add(imageExtraMenu);
  385. }
  386. }
  387. break;
  388. case CommandType.Copy:
  389. e.DoCommand();
  390. break;
  391. case CommandType.Cut:
  392. case CommandType.Paste:
  393. case CommandType.Delete:
  394. e.DoCommand();
  395. break;
  396. default:
  397. break;
  398. }
  399. }
  400. private void CopyImage_Click(object sender, RoutedEventArgs e)
  401. {
  402. try
  403. {
  404. Dictionary<int, List<Bitmap>> imageDict = PdfViewControl.PDFView?.GetSelectedImages();
  405. if (imageDict != null && imageDict.Count > 0)
  406. {
  407. foreach (int pageIndex in imageDict.Keys)
  408. {
  409. List<Bitmap> imageList = imageDict[pageIndex];
  410. foreach (Bitmap image in imageList)
  411. {
  412. MemoryStream ms = new MemoryStream();
  413. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  414. BitmapImage imageData = new BitmapImage();
  415. imageData.BeginInit();
  416. imageData.StreamSource = ms;
  417. imageData.CacheOption = BitmapCacheOption.OnLoad;
  418. imageData.EndInit();
  419. imageData.Freeze();
  420. Clipboard.SetImage(imageData);
  421. break;
  422. }
  423. }
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. }
  429. }
  430. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  431. {
  432. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  433. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  434. {
  435. string choosePath = folderDialog.SelectedPath;
  436. string openPath = choosePath;
  437. try
  438. {
  439. Dictionary<int, List<Bitmap>> imageDict = PdfViewControl.PDFView?.GetSelectedImages();
  440. if (imageDict != null && imageDict.Count > 0)
  441. {
  442. foreach (int pageIndex in imageDict.Keys)
  443. {
  444. List<Bitmap> imageList = imageDict[pageIndex];
  445. foreach (Bitmap image in imageList)
  446. {
  447. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  448. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  449. openPath = savePath;
  450. }
  451. }
  452. }
  453. Process.Start("explorer", "/select,\"" + openPath + "\"");
  454. }
  455. catch (Exception ex)
  456. {
  457. }
  458. }
  459. }
  460. #endregion
  461. #region UI
  462. private double CheckZoomLevel(double zoom, bool IsGrowth)
  463. {
  464. double standardZoom = 100;
  465. if (zoom <= 0.01)
  466. {
  467. return 0.01;
  468. }
  469. if (zoom >= 10)
  470. {
  471. return 10;
  472. }
  473. zoom *= 100;
  474. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  475. {
  476. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  477. {
  478. standardZoom = zoomLevelList[i + 1];
  479. break;
  480. }
  481. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  482. {
  483. standardZoom = zoomLevelList[i];
  484. break;
  485. }
  486. }
  487. return standardZoom / 100;
  488. }
  489. private void ToolExpand_Click(object sender, RoutedEventArgs e)
  490. {
  491. ToggleButton expandBtn = sender as ToggleButton;
  492. if (expandBtn != null)
  493. {
  494. bool isExpand = expandBtn.IsChecked == true;
  495. ExpandLeftPanel(isExpand);
  496. }
  497. }
  498. private void EditLink_Click(object sender, RoutedEventArgs e)
  499. {
  500. PropertyContainer.Visibility = Visibility.Visible;
  501. }
  502. private void UndoButton_Click(object sender, RoutedEventArgs e)
  503. {
  504. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  505. {
  506. PdfViewControl.PDFView.UndoManager?.Undo();
  507. }
  508. }
  509. private void RedoButton_Click(object sender, RoutedEventArgs e)
  510. {
  511. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  512. {
  513. PdfViewControl.PDFView.UndoManager?.Redo();
  514. }
  515. }
  516. #endregion
  517. #region Property changed
  518. protected void OnPropertyChanged([CallerMemberName] string name = null)
  519. {
  520. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  521. }
  522. public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  523. {
  524. OnPropertyChanged(e.PropertyName);
  525. if (e.PropertyName == "CanSave")
  526. {
  527. OnCanSaveChanged?.Invoke(this, CanSave);
  528. }
  529. }
  530. #endregion
  531. #region Event handle
  532. private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
  533. {
  534. PDFAnnotationControl.AnnotationCancel();
  535. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  536. //AnnotationBarBtn.IsChecked = false;
  537. //ViewSettingBtn.IsChecked = false;
  538. }
  539. private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
  540. {
  541. PDFAnnotationControl.LoadAnnotationPanel(e);
  542. if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
  543. {
  544. ExpandRightPropertyPanel(PDFAnnotationControl, Visibility.Visible);
  545. //AnnotationBarBtn.IsChecked = true;
  546. }
  547. }
  548. private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  549. {
  550. PropertyContainer.Child = PDFAnnotationControl;
  551. PDFAnnotationControl.SetAnnotEventData(e);
  552. }
  553. private void PDFView_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  554. {
  555. //BotaSideTool.LoadAnnotationList();
  556. OnAnnotEditHandler.Invoke(this, null);
  557. }
  558. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  559. {
  560. if (e.Key == "Zoom")
  561. {
  562. //CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  563. }
  564. }
  565. #endregion
  566. public void ClearViewerControl()
  567. {
  568. PDFGrid.Child = null;
  569. BotaContainer.Child = null;
  570. }
  571. }
  572. }