AnnotationControl.xaml.cs 24 KB

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