AnnotationControl.xaml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. PDFViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
  203. PDFViewControl.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
  204. PDFViewControl.PDFViewTool.AnnotChanged -= PDFViewTool_AnnotChanged;
  205. PDFViewControl.PDFViewTool.AnnotChanged += PDFViewTool_AnnotChanged;
  206. PDFViewControl.PDFToolManager.CreatePolygonFinished -= PDFToolManager_CreatePolygonFinished;
  207. PDFViewControl.PDFToolManager.CreatePolygonFinished += PDFToolManager_CreatePolygonFinished;
  208. }
  209. private void PDFToolManager_CreatePolygonFinished(object sender, EventArgs e)
  210. {
  211. PDFAnnotationControl.ClearPanel();
  212. }
  213. private void PDFViewTool_AnnotChanged(object sender, object e)
  214. {
  215. OnAnnotEditHandler?.Invoke(this, EventArgs.Empty);
  216. }
  217. private void PDFToolManager_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  218. {
  219. if (e.IsCreate)
  220. {
  221. OnAnnotEditHandler?.Invoke(this, EventArgs.Empty);
  222. }
  223. if(PDFViewControl.GetCacheHitTestAnnot() != null)
  224. {
  225. PDFAnnotationControl.ShowTempAnnotPanel();
  226. }
  227. }
  228. private void PDFViewControl_MouseRightButtonDownHandler(object sender, ComPDFKit.Tool.MouseEventObject e)
  229. {
  230. ContextMenu ContextMenu = PDFViewControl.GetRightMenu();
  231. if (ContextMenu == null)
  232. {
  233. ContextMenu = new ContextMenu();
  234. }
  235. switch (e.hitTestType)
  236. {
  237. case MouseHitTestType.Annot:
  238. case MouseHitTestType.SelectRect:
  239. CreateAnnotContextMenu(sender, ref ContextMenu, e.annotType);
  240. break;
  241. case MouseHitTestType.Text:
  242. CreateSelectTextContextMenu(sender, ref ContextMenu);
  243. break;
  244. case MouseHitTestType.ImageSelect:
  245. CreateSelectImageContextMenu(sender, ref ContextMenu);
  246. break;
  247. default:
  248. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  249. PDFViewControl.CreateViewerMenu(sender, ref ContextMenu);
  250. break;
  251. }
  252. PDFViewControl.SetRightMenu(ContextMenu);
  253. }
  254. private void CreateSelectTextContextMenu(object sender, ref ContextMenu menu)
  255. {
  256. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  257. }
  258. private void CreateAnnotContextMenu(object sender, ref ContextMenu menu, C_ANNOTATION_TYPE annotType)
  259. {
  260. switch (annotType)
  261. {
  262. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  263. break;
  264. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  265. case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
  266. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  267. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  268. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Play"), Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = (sender as CPDFViewerTool).GetCacheHitTestAnnot() });
  269. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  270. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  271. break;
  272. default:
  273. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  274. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  275. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  276. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  277. break;
  278. }
  279. }
  280. private void CreateSelectImageContextMenu(object sender, ref ContextMenu menu)
  281. {
  282. if (menu == null)
  283. {
  284. menu = new ContextMenu();
  285. }
  286. MenuItem copyImage = new MenuItem();
  287. copyImage.Header = "Copy Image";
  288. copyImage.Click += CopyImage_Click;
  289. menu.Items.Add(copyImage);
  290. MenuItem extractImage = new MenuItem();
  291. extractImage.Header = "Extract Image";
  292. extractImage.Click += ExtractImage_Click;
  293. menu.Items.Add(extractImage);
  294. }
  295. private void ExtractImage_Click(object sender, RoutedEventArgs e)
  296. {
  297. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  298. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  299. {
  300. PageImageItem image = null;
  301. Dictionary<int, List<PageImageItem>> pageImageDict = PDFViewControl.FocusPDFViewTool.GetSelectImageItems();
  302. if (pageImageDict != null && pageImageDict.Count > 0)
  303. {
  304. foreach (int pageIndex in pageImageDict.Keys)
  305. {
  306. List<PageImageItem> imageItemList = pageImageDict[pageIndex];
  307. image = imageItemList[0];
  308. break;
  309. }
  310. }
  311. if (image == null)
  312. {
  313. return;
  314. }
  315. CPDFPage page = PDFViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
  316. string savePath = Path.Combine(folderDialog.SelectedPath, Guid.NewGuid() + ".jpg");
  317. string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
  318. page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
  319. Bitmap bitmap = new Bitmap(tempPath);
  320. bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  321. Process.Start("explorer", "/select,\"" + savePath + "\"");
  322. }
  323. }
  324. private void CopyImage_Click(object sender, RoutedEventArgs e)
  325. {
  326. PageImageItem image = null;
  327. Dictionary<int, List<PageImageItem>> pageImageDict = PDFViewControl.FocusPDFViewTool.GetSelectImageItems();
  328. if (pageImageDict != null && pageImageDict.Count > 0)
  329. {
  330. foreach (int pageIndex in pageImageDict.Keys)
  331. {
  332. List<PageImageItem> imageItemList = pageImageDict[pageIndex];
  333. image = imageItemList[0];
  334. break;
  335. }
  336. }
  337. if (image == null)
  338. {
  339. return;
  340. }
  341. CPDFPage page = PDFViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
  342. string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
  343. page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
  344. Bitmap bitmap = new Bitmap(tempPath);
  345. BitmapImage imageData;
  346. using (MemoryStream ms = new MemoryStream())
  347. {
  348. bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  349. imageData = new BitmapImage();
  350. imageData.BeginInit();
  351. imageData.StreamSource = ms;
  352. imageData.CacheOption = BitmapCacheOption.OnLoad;
  353. imageData.EndInit();
  354. imageData.Freeze();
  355. Clipboard.SetImage(imageData);
  356. bitmap.Dispose();
  357. File.Delete(tempPath);
  358. }
  359. }
  360. public void UnloadEvent()
  361. {
  362. panelState.PropertyChanged -= PanelState_PropertyChanged;
  363. PDFAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  364. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  365. PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
  366. PDFAnnotationControl.UnLoadPDFViewHandler();
  367. }
  368. private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
  369. {
  370. AnnotationBarControl.ClearAllToolState();
  371. }
  372. public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
  373. {
  374. this.PropertyContainer.Child = displaySettingsControl;
  375. this.PropertyContainer.Visibility = visibility;
  376. }
  377. #endregion
  378. #region Expand and collapse Panel
  379. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  380. {
  381. PropertyContainer.Width = 260;
  382. PropertyContainer.Child = propertytPanel;
  383. PropertyContainer.Visibility = visible;
  384. }
  385. public void ExpandLeftPanel(bool isExpand)
  386. {
  387. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  388. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  389. if (isExpand)
  390. {
  391. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  392. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  393. }
  394. else
  395. {
  396. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  397. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  398. }
  399. }
  400. #endregion
  401. #region UI
  402. private double CheckZoomLevel(double zoom, bool IsGrowth)
  403. {
  404. double standardZoom = 100;
  405. if (zoom <= 0.01)
  406. {
  407. return 0.01;
  408. }
  409. if (zoom >= 10)
  410. {
  411. return 10;
  412. }
  413. zoom *= 100;
  414. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  415. {
  416. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  417. {
  418. standardZoom = zoomLevelList[i + 1];
  419. break;
  420. }
  421. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  422. {
  423. standardZoom = zoomLevelList[i];
  424. break;
  425. }
  426. }
  427. return standardZoom / 100;
  428. }
  429. private void ToolExpand_Click(object sender, RoutedEventArgs e)
  430. {
  431. ToggleButton expandBtn = sender as ToggleButton;
  432. if (expandBtn != null)
  433. {
  434. bool isExpand = expandBtn.IsChecked == true;
  435. ExpandLeftPanel(isExpand);
  436. }
  437. }
  438. private void EditLink_Click(object sender, RoutedEventArgs e)
  439. {
  440. PropertyContainer.Visibility = Visibility.Visible;
  441. }
  442. private void UndoButton_Click(object sender, RoutedEventArgs e)
  443. {
  444. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  445. {
  446. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  447. PDFViewControl.PDFToolManager.ClearSelect();
  448. PDFViewControl.PDFViewTool.GetCPDFViewer().UpdateAnnotFrame();
  449. (BotaContainer.Child as CPDFBOTABarControl).LoadAnnotationList();
  450. }
  451. }
  452. private void RedoButton_Click(object sender, RoutedEventArgs e)
  453. {
  454. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null)
  455. {
  456. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  457. PDFViewControl.PDFToolManager.ClearSelect();
  458. PDFViewControl.PDFViewTool.GetCPDFViewer().UpdateAnnotFrame();
  459. (BotaContainer.Child as CPDFBOTABarControl).LoadAnnotationList();
  460. }
  461. }
  462. #endregion
  463. #region Property changed
  464. protected void OnPropertyChanged([CallerMemberName] string name = null)
  465. {
  466. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  467. }
  468. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  469. {
  470. OnPropertyChanged(e.PropertyName);
  471. OnCanSaveChanged?.Invoke(this, CanSave);
  472. }
  473. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  474. {
  475. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  476. {
  477. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  478. }
  479. else if (e.PropertyName == nameof(PanelState.RightPanel))
  480. {
  481. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  482. {
  483. ExpandRightPropertyPanel(PDFAnnotationControl, Visibility.Visible);
  484. }
  485. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  486. {
  487. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  488. }
  489. else
  490. {
  491. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  492. }
  493. }
  494. }
  495. #endregion
  496. #region Event handle
  497. private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
  498. {
  499. PDFAnnotationControl.AnnotationCancel();
  500. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  501. {
  502. panelState.RightPanel = PanelState.RightPanelState.None;
  503. }
  504. }
  505. private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
  506. {
  507. PDFAnnotationControl.LoadAnnotationPanel(e);
  508. if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
  509. {
  510. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  511. }
  512. if (e == CPDFAnnotationType.Link)
  513. {
  514. PDFViewControl.PDFViewTool.GetCPDFViewer().SetLinkHighlight(true);
  515. }
  516. }
  517. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  518. {
  519. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanUndo)
  520. {
  521. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Undo();
  522. PDFViewControl.PDFToolManager.ClearSelect();
  523. PDFViewControl.PDFViewTool.GetCPDFViewer().UpdateAnnotFrame();
  524. (BotaContainer.Child as CPDFBOTABarControl).LoadAnnotationList();
  525. }
  526. }
  527. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  528. {
  529. if (PDFViewControl != null && PDFViewControl.PDFViewTool.GetCPDFViewer() != null && CanRedo)
  530. {
  531. PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager?.Redo();
  532. PDFViewControl.PDFToolManager.ClearSelect();
  533. PDFViewControl.PDFViewTool.GetCPDFViewer().UpdateAnnotFrame();
  534. (BotaContainer.Child as CPDFBOTABarControl).LoadAnnotationList();
  535. }
  536. }
  537. private void CommandBinding_Executed_Highlight(object sender, ExecutedRoutedEventArgs e)
  538. {
  539. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Highlight);
  540. }
  541. private void CommandBinding_Executed_Underline(object sender, ExecutedRoutedEventArgs e)
  542. {
  543. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Underline);
  544. }
  545. private void CommandBinding_Executed_Strikeout(object sender, ExecutedRoutedEventArgs e)
  546. {
  547. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Strikeout);
  548. }
  549. private void CommandBinding_Executed_Squiggly(object sender, ExecutedRoutedEventArgs e)
  550. {
  551. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Squiggly);
  552. }
  553. #endregion
  554. }
  555. }