AnnotationControl.xaml.cs 25 KB

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