AnnotationControl.xaml.cs 27 KB

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