AnnotationControl.xaml.cs 29 KB

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