AnnotationControl.xaml.cs 25 KB

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