AnnotationControl.xaml.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. using System.Windows.Controls;
  2. using ComPDFKit.Controls.Data;
  3. using System;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Runtime.CompilerServices;
  9. using System.Windows;
  10. using System.Windows.Controls.Primitives;
  11. using System.Windows.Input;
  12. using System.Windows.Media.Imaging;
  13. using ComPDFKit.Controls.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
  14. using ComPDFKit.Controls.Helper;
  15. using ComPDFKit.PDFAnnotation.Form;
  16. using ComPDFKit.PDFAnnotation;
  17. using ComPDFKit.Tool;
  18. using ComPDFKit.PDFPage;
  19. using ComPDFKitViewer.Widget;
  20. using ComPDFKit.Tool.Help;
  21. namespace ComPDFKit.Controls.PDFControl
  22. {
  23. public partial class AnnotationControl : UserControl, INotifyPropertyChanged
  24. {
  25. #region Property
  26. private bool isFirstLoad = true;
  27. public PDFViewControl PDFViewControl;
  28. public CPDFAnnotationControl PDFAnnotationControl = null;
  29. private CPDFDisplaySettingsControl displaySettingsControl = null;
  30. public FromPropertyControl FromPropertyControl = new FromPropertyControl();
  31. private PanelState panelState = PanelState.GetInstance();
  32. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  33. public event PropertyChangedEventHandler PropertyChanged;
  34. public ICommand CloseTabCommand;
  35. public ICommand ExpandPropertyPanelCommand;
  36. public bool CanUndo
  37. {
  38. get
  39. {
  40. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  41. {
  42. return PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanUndo;
  43. }
  44. return false;
  45. }
  46. }
  47. public bool CanRedo
  48. {
  49. get
  50. {
  51. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  52. {
  53. return PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanRedo;
  54. }
  55. return false;
  56. }
  57. }
  58. private bool CanSave
  59. {
  60. get
  61. {
  62. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  63. {
  64. if (PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanRedo ||
  65. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanUndo)
  66. {
  67. return true;
  68. }
  69. }
  70. return false;
  71. }
  72. }
  73. public event EventHandler<bool> OnCanSaveChanged;
  74. public event EventHandler OnAnnotEditHandler;
  75. #endregion
  76. public AnnotationControl()
  77. {
  78. InitializeComponent();
  79. DataContext = this;
  80. PDFAnnotationControl = new CPDFAnnotationControl();
  81. CPDFAnnotationType[] annotationProperties =
  82. {
  83. CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout,
  84. CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText,
  85. CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square,
  86. CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Image,
  87. CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link,
  88. CPDFAnnotationType.Audio
  89. };
  90. AnnotationBarControl.InitAnnotationBar(annotationProperties);
  91. UndoBtn.ToolTip = LanguageHelper.CommonManager.GetString("Tooltip_Undo");
  92. RedoBtn.ToolTip = LanguageHelper.CommonManager.GetString("Tooltip_Redo");
  93. }
  94. #region Init PDFViewer
  95. public void InitWithPDFViewer(PDFViewControl pdfViewer)
  96. {
  97. PDFViewControl = pdfViewer;
  98. PDFGrid.Child = PDFViewControl;
  99. FloatPageTool.InitWithPDFViewer(PDFViewControl);
  100. InitialPDFViewControl(PDFViewControl);
  101. }
  102. #endregion
  103. #region Public Method
  104. public void ClearViewerControl()
  105. {
  106. PDFGrid.Child = null;
  107. BotaContainer.Child = null;
  108. PropertyContainer.Child = null;
  109. displaySettingsControl = null;
  110. PDFViewControl?.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_NONE);
  111. }
  112. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  113. {
  114. this.BotaContainer.Child = botaControl;
  115. }
  116. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  117. {
  118. this.displaySettingsControl = displaySettingsControl;
  119. }
  120. public void SetPropertyContainer(UIElement uiElement)
  121. {
  122. PropertyContainer.Child = uiElement;
  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 UserControl_Loaded(object sender, RoutedEventArgs e)
  135. {
  136. PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
  137. PDFViewControl.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
  138. InitialPDFViewControl(PDFViewControl);
  139. }
  140. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  141. {
  142. if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  143. {
  144. BaseWidget baseWidget = PDFViewControl.GetCacheHitTestWidget();
  145. if (baseWidget != null)
  146. {
  147. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  148. PDFViewControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  149. baseWidget.GetAnnotData().PageIndex,
  150. baseWidget.GetAnnotData().Annot);
  151. if ((annotParam as WidgetParm).WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
  152. {
  153. CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
  154. signatureProperty.SetFormProperty(annotParam, PDFViewControl, baseWidget.GetAnnotData().Annot);
  155. PropertyContainer.Child = signatureProperty;
  156. }
  157. }
  158. }
  159. }
  160. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  161. {
  162. PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
  163. }
  164. private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
  165. {
  166. AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
  167. AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
  168. AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
  169. AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
  170. }
  171. private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
  172. {
  173. AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
  174. AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
  175. }
  176. #endregion
  177. #region Annotation
  178. public void InitialPDFViewControl(PDFViewControl newPDFViewer)
  179. {
  180. PDFAnnotationControl.SetPDFViewer(newPDFViewer);
  181. PDFAnnotationControl.AnnotationCancel();
  182. AnnotationBarControl.ClearAllToolState();
  183. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  184. PDFAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  185. PDFAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
  186. panelState.PropertyChanged -= PanelState_PropertyChanged;
  187. panelState.PropertyChanged += PanelState_PropertyChanged;
  188. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  189. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  190. PDFAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  191. PDFViewControl.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
  192. PDFViewControl.PDFViewTool.AnnotChanged -= PDFViewTool_AnnotChanged;
  193. PDFViewControl.PDFViewTool.AnnotChanged += PDFViewTool_AnnotChanged;
  194. }
  195. private void PDFViewTool_AnnotChanged(object sender, object e)
  196. {
  197. OnAnnotEditHandler?.Invoke(this, EventArgs.Empty);
  198. }
  199. private void PDFToolManager_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  200. {
  201. if (e.IsCreate)
  202. {
  203. OnAnnotEditHandler?.Invoke(this, EventArgs.Empty);
  204. }
  205. }
  206. private void PDFViewControl_MouseRightButtonDownHandler(object sender, ComPDFKit.Tool.MouseEventObject e)
  207. {
  208. ContextMenu ContextMenu = PDFViewControl.GetRightMenu();
  209. if (ContextMenu == null)
  210. {
  211. ContextMenu = new ContextMenu();
  212. }
  213. switch (e.hitTestType)
  214. {
  215. case MouseHitTestType.Annot:
  216. case MouseHitTestType.SelectRect:
  217. CreateAnnotContextMenu(sender, ref ContextMenu, e.annotType);
  218. break;
  219. case MouseHitTestType.Text:
  220. CreateSelectTextContextMenu(sender, ref ContextMenu);
  221. break;
  222. case MouseHitTestType.ImageSelect:
  223. CreateSelectImageContextMenu(sender, ref ContextMenu);
  224. break;
  225. default:
  226. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  227. PDFViewControl.CreateViewerMenu(sender, ref ContextMenu);
  228. break;
  229. }
  230. PDFViewControl.SetRightMenu(ContextMenu);
  231. }
  232. private void CreateSelectTextContextMenu(object sender, ref ContextMenu menu)
  233. {
  234. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  235. }
  236. private void CreateAnnotContextMenu(object sender, ref ContextMenu menu, C_ANNOTATION_TYPE annotType)
  237. {
  238. switch (annotType)
  239. {
  240. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  241. break;
  242. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  243. case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
  244. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  245. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  246. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Play"), Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = (sender as CPDFViewerTool).GetCacheHitTestAnnot() });
  247. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  248. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  249. break;
  250. default:
  251. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  252. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  253. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  254. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  255. break;
  256. }
  257. }
  258. private void CreateSelectImageContextMenu(object sender, ref ContextMenu menu)
  259. {
  260. if (menu == null)
  261. {
  262. menu = new ContextMenu();
  263. }
  264. MenuItem copyImage = new MenuItem();
  265. copyImage.Header = "Copy Image";
  266. copyImage.Click += CopyImage_Click;
  267. menu.Items.Add(copyImage);
  268. MenuItem extractImage = new MenuItem();
  269. extractImage.Header = "Extract Image";
  270. extractImage.Click += ExtractImage_Click;
  271. menu.Items.Add(extractImage);
  272. }
  273. private void ExtractImage_Click(object sender, RoutedEventArgs e)
  274. {
  275. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  276. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  277. {
  278. var image = PDFViewControl.FocusPDFViewTool.GetSelectImage();
  279. if (image == null)
  280. {
  281. return;
  282. }
  283. CPDFPage page = PDFViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
  284. string savePath = Path.Combine(folderDialog.SelectedPath, Guid.NewGuid() + ".jpg");
  285. string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
  286. page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
  287. Bitmap bitmap = new Bitmap(tempPath);
  288. bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  289. Process.Start("explorer", "/select,\"" + savePath + "\"");
  290. }
  291. }
  292. private void CopyImage_Click(object sender, RoutedEventArgs e)
  293. {
  294. var image = PDFViewControl.FocusPDFViewTool.GetSelectImage();
  295. if (image == null)
  296. {
  297. return;
  298. }
  299. CPDFPage page = PDFViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
  300. string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
  301. page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
  302. Bitmap bitmap = new Bitmap(tempPath);
  303. BitmapImage imageData;
  304. using (MemoryStream ms = new MemoryStream())
  305. {
  306. bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  307. imageData = new BitmapImage();
  308. imageData.BeginInit();
  309. imageData.StreamSource = ms;
  310. imageData.CacheOption = BitmapCacheOption.OnLoad;
  311. imageData.EndInit();
  312. imageData.Freeze();
  313. Clipboard.SetImage(imageData);
  314. bitmap.Dispose();
  315. File.Delete(tempPath);
  316. }
  317. }
  318. public void UnloadEvent()
  319. {
  320. panelState.PropertyChanged -= PanelState_PropertyChanged;
  321. PDFAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  322. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  323. PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
  324. PDFAnnotationControl.UnLoadPDFViewHandler();
  325. }
  326. private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
  327. {
  328. AnnotationBarControl.ClearAllToolState();
  329. }
  330. public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
  331. {
  332. this.PropertyContainer.Child = displaySettingsControl;
  333. this.PropertyContainer.Visibility = visibility;
  334. }
  335. #endregion
  336. #region Expand and collapse Panel
  337. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  338. {
  339. PropertyContainer.Width = 260;
  340. PropertyContainer.Child = propertytPanel;
  341. PropertyContainer.Visibility = visible;
  342. }
  343. public void ExpandLeftPanel(bool isExpand)
  344. {
  345. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  346. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  347. if (isExpand)
  348. {
  349. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  350. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  351. }
  352. else
  353. {
  354. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  355. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  356. }
  357. }
  358. #endregion
  359. #region UI
  360. private double CheckZoomLevel(double zoom, bool IsGrowth)
  361. {
  362. double standardZoom = 100;
  363. if (zoom <= 0.01)
  364. {
  365. return 0.01;
  366. }
  367. if (zoom >= 10)
  368. {
  369. return 10;
  370. }
  371. zoom *= 100;
  372. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  373. {
  374. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  375. {
  376. standardZoom = zoomLevelList[i + 1];
  377. break;
  378. }
  379. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  380. {
  381. standardZoom = zoomLevelList[i];
  382. break;
  383. }
  384. }
  385. return standardZoom / 100;
  386. }
  387. private void ToolExpand_Click(object sender, RoutedEventArgs e)
  388. {
  389. ToggleButton expandBtn = sender as ToggleButton;
  390. if (expandBtn != null)
  391. {
  392. bool isExpand = expandBtn.IsChecked == true;
  393. ExpandLeftPanel(isExpand);
  394. }
  395. }
  396. private void EditLink_Click(object sender, RoutedEventArgs e)
  397. {
  398. PropertyContainer.Visibility = Visibility.Visible;
  399. }
  400. private void UndoButton_Click(object sender, RoutedEventArgs e)
  401. {
  402. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  403. {
  404. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  405. PDFViewControl.PDFToolManager.ClearSelect();
  406. PDFViewControl.PDFViewTool.GetCPDFViewer().UpdateAnnotFrame();
  407. (BotaContainer.Child as CPDFBOTABarControl).LoadAnnotationList();
  408. }
  409. }
  410. private void RedoButton_Click(object sender, RoutedEventArgs e)
  411. {
  412. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  413. {
  414. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  415. PDFViewControl.PDFToolManager.ClearSelect();
  416. PDFViewControl.PDFViewTool.GetCPDFViewer().UpdateAnnotFrame();
  417. (BotaContainer.Child as CPDFBOTABarControl).LoadAnnotationList();
  418. }
  419. }
  420. #endregion
  421. #region Property changed
  422. protected void OnPropertyChanged([CallerMemberName] string name = null)
  423. {
  424. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  425. }
  426. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  427. {
  428. OnPropertyChanged(e.PropertyName);
  429. }
  430. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  431. {
  432. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  433. {
  434. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  435. }
  436. else if (e.PropertyName == nameof(PanelState.RightPanel))
  437. {
  438. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  439. {
  440. ExpandRightPropertyPanel(PDFAnnotationControl, Visibility.Visible);
  441. }
  442. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  443. {
  444. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  445. }
  446. else
  447. {
  448. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  449. }
  450. }
  451. }
  452. #endregion
  453. #region Event handle
  454. private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
  455. {
  456. PDFAnnotationControl.AnnotationCancel();
  457. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  458. {
  459. panelState.RightPanel = PanelState.RightPanelState.None;
  460. }
  461. }
  462. private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
  463. {
  464. PDFAnnotationControl.LoadAnnotationPanel(e);
  465. if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
  466. {
  467. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  468. }
  469. if (e == CPDFAnnotationType.Link)
  470. {
  471. PDFViewControl.PDFViewTool.GetCPDFViewer().SetLinkHighlight(true);
  472. }
  473. }
  474. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  475. {
  476. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  477. {
  478. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  479. }
  480. }
  481. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  482. {
  483. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanRedo)
  484. {
  485. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  486. }
  487. }
  488. private void CommandBinding_Executed_Highlight(object sender, ExecutedRoutedEventArgs e)
  489. {
  490. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Highlight);
  491. }
  492. private void CommandBinding_Executed_Underline(object sender, ExecutedRoutedEventArgs e)
  493. {
  494. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Underline);
  495. }
  496. private void CommandBinding_Executed_Strikeout(object sender, ExecutedRoutedEventArgs e)
  497. {
  498. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Strikeout);
  499. }
  500. private void CommandBinding_Executed_Squiggly(object sender, ExecutedRoutedEventArgs e)
  501. {
  502. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Squiggly);
  503. }
  504. #endregion
  505. }
  506. }