PDFViewControl.xaml.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFAnnotation.Form;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.Tool;
  5. using ComPDFKit.Tool.SettingParam;
  6. using Compdfkit_Tools.PDFControlUI;
  7. using ComPDFKitViewer;
  8. using ComPDFKitViewer.BaseObject;
  9. using ComPDFKitViewer.Widget;
  10. using Nager.Country.Currencies;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Diagnostics;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Input;
  19. using Compdfkit_Tools.Helper;
  20. using ComPDFKit.Tool.DrawTool;
  21. using static ComPDFKit.Tool.CPDFToolManager;
  22. using static Compdfkit_Tools.PDFControlUI.CPDFViewModeUI;
  23. using SplitMode = Compdfkit_Tools.PDFControlUI.CPDFViewModeUI.SplitMode;
  24. namespace Compdfkit_Tools.PDFControl
  25. {
  26. public partial class PDFViewControl : UserControl
  27. {
  28. private CPDFViewerTool splitViewerTool;
  29. private CPDFToolManager splitToolManager;
  30. private CPDFViewerTool viewerTool;
  31. private CPDFToolManager toolManager;
  32. public CPDFViewerTool PDFViewTool { get; private set; }
  33. public CPDFToolManager PDFToolManager { get; private set; }
  34. public CPDFViewerTool FocusPDFViewTool { get; private set; }
  35. //public event EventHandler SplitPDFViewToolCreated;
  36. public event EventHandler FocusPDFViewToolChanged;
  37. public event EventHandler<MouseEventObject> MouseLeftButtonDownHandler;
  38. public event EventHandler<MouseEventObject> MouseLeftButtonUpHandler;
  39. public event EventHandler<MouseEventObject> MouseMoveHandler;
  40. public event EventHandler<MouseEventObject> MouseRightButtonDownHandler;
  41. public event EventHandler<ComPDFKitViewer.MouseWheelZoomArgs> MouseWheelZoomHandler;
  42. public event EventHandler DrawChanged;
  43. //private ContextMenu RightMenu;
  44. #region Properties
  45. private double splitWidthScale = 0.5;
  46. private double splitHeightScale = 0.5;
  47. public bool CustomSignHandle { get; set; }
  48. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  49. #endregion
  50. public PDFViewControl()
  51. {
  52. InitializeComponent();
  53. viewerTool = new CPDFViewerTool();
  54. toolManager = new CPDFToolManager(viewerTool);
  55. Loaded += PDFViewControl_Loaded;
  56. PDFViewTool = viewerTool;
  57. PDFToolManager = toolManager;
  58. PDFToolManager.SetToolType(CPDFToolManager.ToolType.Viewer);
  59. splitViewerTool = new CPDFViewerTool();
  60. splitToolManager = new CPDFToolManager(splitViewerTool);
  61. splitToolManager.SetToolType(CPDFToolManager.ToolType.Viewer);
  62. FocusPDFViewTool = viewerTool;
  63. PDFView.Child = PDFViewTool;
  64. VerticalView.Child = splitViewerTool;
  65. PDFViewTool.SizeChanged -= PDFViewTool_SizeChanged;
  66. PDFViewTool.GetCPDFViewer().MouseWheelZoomHandler -= PDFViewControl_MouseWheelZoomHandler;
  67. PDFViewTool.DrawChanged -= PDFViewTool_DrawChanged;
  68. PDFToolManager.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  69. PDFToolManager.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
  70. PDFToolManager.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
  71. PDFToolManager.AnnotDefaultEditedHandler -= PDFToolManager_AnnotDefaultEditedHandler;
  72. PDFToolManager.MouseRightButtonDownHandler -= PDFToolManager_MouseRightButtonDownHandler;
  73. PDFViewTool.SizeChanged += PDFViewTool_SizeChanged;
  74. PDFViewTool.GetCPDFViewer().MouseWheelZoomHandler += PDFViewControl_MouseWheelZoomHandler;
  75. PDFViewTool.DrawChanged += PDFViewTool_DrawChanged;
  76. PDFToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
  77. PDFToolManager.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
  78. PDFToolManager.MouseMoveHandler += PDFToolManager_MouseMoveHandler;
  79. PDFToolManager.AnnotDefaultEditedHandler += PDFToolManager_AnnotDefaultEditedHandler;
  80. PDFToolManager.MouseRightButtonDownHandler += PDFToolManager_MouseRightButtonDownHandler;
  81. splitViewerTool.SizeChanged -= SplitViewerTool_SizeChanged;
  82. splitViewerTool.GetCPDFViewer().MouseWheelZoomHandler -= SplitPDFViewControl_MouseWheelZoomHandler;
  83. splitViewerTool.DrawChanged -= PDFViewTool_DrawChanged;
  84. splitToolManager.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  85. splitToolManager.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
  86. splitToolManager.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
  87. splitToolManager.AnnotDefaultEditedHandler -= PDFToolManager_AnnotDefaultEditedHandler;
  88. splitToolManager.MouseRightButtonDownHandler -= PDFToolManager_MouseRightButtonDownHandler;
  89. splitViewerTool.SizeChanged += SplitViewerTool_SizeChanged;
  90. splitViewerTool.GetCPDFViewer().MouseWheelZoomHandler += SplitPDFViewControl_MouseWheelZoomHandler;
  91. splitViewerTool.DrawChanged += PDFViewTool_DrawChanged;
  92. splitToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
  93. splitToolManager.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
  94. splitToolManager.MouseMoveHandler += PDFToolManager_MouseMoveHandler;
  95. splitToolManager.AnnotDefaultEditedHandler += PDFToolManager_AnnotDefaultEditedHandler;
  96. splitToolManager.MouseRightButtonDownHandler += PDFToolManager_MouseRightButtonDownHandler;
  97. }
  98. private void PDFToolManager_AnnotDefaultEditedHandler(object sender, SelectedAnnotData e)
  99. {
  100. UpdateAnnotFrame();
  101. }
  102. private void PDFViewControl_Loaded(object sender, RoutedEventArgs e)
  103. {
  104. RemoveSplitViewerTool();
  105. }
  106. private void PDFViewTool_DrawChanged(object sender, EventArgs e)
  107. {
  108. DrawChanged?.Invoke(sender, e);
  109. }
  110. public ContextMenu GetRightMenu()
  111. {
  112. FocusPDFViewTool.ContextMenu?.Items.Clear();
  113. return FocusPDFViewTool.ContextMenu;
  114. }
  115. public void SetRightMenu(ContextMenu contextMenu)
  116. {
  117. FocusPDFViewTool.ContextMenu = contextMenu;
  118. }
  119. private void PDFToolManager_MouseRightButtonDownHandler(object sender, MouseEventObject e)
  120. {
  121. Point point = e.mouseButtonEventArgs.GetPosition(this);
  122. viewerTool.GetCPDFViewer().GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
  123. if(index == -1)
  124. {
  125. viewerTool.ContextMenu = null;
  126. return;
  127. }
  128. PDFViewTool.SetPastePoint(point);
  129. MouseRightButtonDownHandler?.Invoke(sender, e);
  130. }
  131. private void PDFToolManager_MouseMoveHandler(object sender, MouseEventObject e)
  132. {
  133. MouseMoveHandler?.Invoke(this, e);
  134. }
  135. private void PDFToolManager_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  136. {
  137. MouseLeftButtonUpHandler?.Invoke(sender, e);
  138. }
  139. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  140. {
  141. MouseLeftButtonDownHandler?.Invoke(sender, e);
  142. }
  143. private void PDFViewTool_SizeChanged(object sender, SizeChangedEventArgs e)
  144. {
  145. PDFViewTool.GetCPDFViewer().UpdateRenderFrame();
  146. }
  147. private void SplitViewerTool_SizeChanged(object sender, SizeChangedEventArgs e)
  148. {
  149. if (VerticalView.Visibility == Visibility.Visible)
  150. {
  151. splitWidthScale = VerticalView.ActualWidth / ViewToolGrid.ActualWidth;
  152. }
  153. if (HorizontalView.Visibility == Visibility.Visible)
  154. {
  155. splitHeightScale = HorizontalView.ActualHeight / ViewToolGrid.ActualHeight;
  156. }
  157. splitViewerTool.GetCPDFViewer().UpdateRenderFrame();
  158. }
  159. public void InitDocument(string Path)
  160. {
  161. CPDFDocument pdfDoc = CPDFDocument.InitWithFilePath(Path);
  162. if (pdfDoc != null)
  163. {
  164. PDFViewTool.GetCPDFViewer().InitDoc(pdfDoc);
  165. PDFViewTool.GetCPDFViewer().SetFitMode(FitMode.FitHeight);
  166. PDFViewTool.GetCPDFViewer().SetViewMode(ViewMode.SingleContinuous);
  167. splitViewerTool.GetCPDFViewer().InitDoc(pdfDoc);
  168. splitViewerTool.GetCPDFViewer().SetFitMode(FitMode.FitHeight);
  169. splitViewerTool.GetCPDFViewer().SetViewMode(ViewMode.SingleContinuous);
  170. }
  171. }
  172. private void PDFViewControl_MouseWheelZoomHandler(object sender, ComPDFKitViewer.MouseWheelZoomArgs e)
  173. {
  174. FocusPDFViewTool = PDFViewTool;
  175. FocusPDFViewToolChanged?.Invoke(this, EventArgs.Empty);
  176. if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
  177. {
  178. e.IsZoom = true;
  179. PDFViewTool.GetCPDFViewer().SetFitMode(FitMode.FitZoom);
  180. double zoom = PDFViewTool.GetCPDFViewer().GetZoom();
  181. PDFViewTool.GetCPDFViewer().SetZoom(CheckZoomLevel(zoom, Convert.ToBoolean(e.WheelBehavior)));
  182. PDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  183. }
  184. MouseWheelZoomHandler?.Invoke(this, e);
  185. }
  186. private void SplitPDFViewControl_MouseWheelZoomHandler(object sender, ComPDFKitViewer.MouseWheelZoomArgs e)
  187. {
  188. FocusPDFViewTool = splitViewerTool;
  189. FocusPDFViewToolChanged?.Invoke(this, EventArgs.Empty);
  190. if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
  191. {
  192. e.IsZoom = true;
  193. splitViewerTool.GetCPDFViewer().SetFitMode(FitMode.FitZoom);
  194. double zoom = splitViewerTool.GetCPDFViewer().GetZoom();
  195. splitViewerTool.GetCPDFViewer().SetZoom(CheckZoomLevel(zoom, Convert.ToBoolean(e.WheelBehavior)));
  196. splitViewerTool?.GetCPDFViewer()?.UpdateRenderFrame();
  197. }
  198. MouseWheelZoomHandler?.Invoke(this, e);
  199. }
  200. public void SetSplitViewMode(SplitMode splitMode)
  201. {
  202. switch (splitMode)
  203. {
  204. case SplitMode.None:
  205. RemoveSplitViewerTool();
  206. break;
  207. case SplitMode.Vertical:
  208. RemoveSplitViewerTool();
  209. if (splitViewerTool != null)
  210. {
  211. VerticalSplitter.Visibility = Visibility.Visible;
  212. VerticalView.Visibility = Visibility.Visible;
  213. ViewToolGrid.ColumnDefinitions[1].Width = new GridLength(15, GridUnitType.Auto);
  214. ViewToolGrid.ColumnDefinitions[2].Width = new GridLength(ViewToolGrid.ActualWidth / 2);
  215. VerticalView.Child = splitViewerTool;
  216. }
  217. break;
  218. case SplitMode.Horizontal:
  219. RemoveSplitViewerTool();
  220. if (splitViewerTool != null)
  221. {
  222. HorizontalSplitter.Visibility = Visibility.Visible;
  223. HorizontalView.Visibility = Visibility.Visible;
  224. ViewToolGrid.RowDefinitions[1].Height = new GridLength(15, GridUnitType.Auto);
  225. ViewToolGrid.RowDefinitions[2].Height = new GridLength(ViewToolGrid.ActualHeight / 2);
  226. HorizontalView.Child = splitViewerTool;
  227. }
  228. break;
  229. }
  230. UpdateRenderFrame();
  231. UpdateAnnotFrame();
  232. }
  233. public void UpdateRenderFrame()
  234. {
  235. viewerTool?.GetCPDFViewer()?.UpdateRenderFrame();
  236. splitViewerTool?.GetCPDFViewer()?.UpdateRenderFrame();
  237. }
  238. public void UpdateAnnotFrame()
  239. {
  240. viewerTool?.GetCPDFViewer()?.UpdateAnnotFrame();
  241. splitViewerTool?.GetCPDFViewer()?.UpdateAnnotFrame();
  242. }
  243. public void SetCropMode(bool isCrop)
  244. {
  245. viewerTool?.GetCPDFViewer()?.SetIsCrop(isCrop);
  246. splitViewerTool?.GetCPDFViewer()?.SetIsCrop(isCrop);
  247. viewerTool?.GetCPDFViewer()?.UpdateVirtualNodes();
  248. splitViewerTool?.GetCPDFViewer()?.UpdateVirtualNodes();
  249. viewerTool?.GetCPDFViewer()?.UpdateRenderFrame();
  250. splitViewerTool?.GetCPDFViewer()?.UpdateRenderFrame();
  251. }
  252. public void SetToolType(ToolType type)
  253. {
  254. toolManager?.SetToolType(type);
  255. splitToolManager?.SetToolType(type);
  256. }
  257. public void SetCreateAnnotType(C_ANNOTATION_TYPE type)
  258. {
  259. toolManager?.SetCreateAnnotType(type);
  260. splitToolManager?.SetCreateAnnotType(type);
  261. }
  262. public void SetCreateWidgetType(C_WIDGET_TYPE type)
  263. {
  264. toolManager?.SetCreateWidgetType(type);
  265. splitToolManager?.SetCreateWidgetType(type);
  266. }
  267. public void SetAnnotParam(AnnotParam param)
  268. {
  269. DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
  270. DefaultSettingParam splitSettingParam = splitViewerTool.GetDefaultSettingParam();
  271. defaultSettingParam.SetAnnotParam(param);
  272. splitSettingParam.SetAnnotParam(param);
  273. }
  274. public void SetIsShowStampMouse(bool isShow)
  275. {
  276. viewerTool?.GetCPDFViewer()?.SetIsShowStampMouse(isShow);
  277. splitViewerTool?.GetCPDFViewer()?.SetIsShowStampMouse(isShow);
  278. }
  279. public void SetDrawModes(DrawModeData drawMode)
  280. {
  281. viewerTool?.GetCPDFViewer()?.SetDrawModes(drawMode.DrawMode);
  282. splitViewerTool?.GetCPDFViewer()?.SetDrawModes(drawMode.DrawMode);
  283. if (drawMode.DrawMode == DrawMode.Custom)
  284. {
  285. viewerTool?.GetCPDFViewer().SetPDFBackground(drawMode.CustomColor);
  286. splitViewerTool?.GetCPDFViewer().SetPDFBackground(drawMode.CustomColor);
  287. }
  288. UpdateRenderFrame();
  289. }
  290. public void SetStampMouseImage(byte[] imageArray, int imageWidth, int imageHeight)
  291. {
  292. viewerTool?.GetCPDFViewer()?.SetStampMouseImage(imageArray, imageWidth, imageHeight);
  293. splitViewerTool?.GetCPDFViewer()?.SetStampMouseImage(imageArray, imageWidth, imageHeight);
  294. }
  295. public bool SetStampMouseImage(string filePath)
  296. {
  297. if ((bool)(viewerTool?.GetCPDFViewer()?.SetStampMouseImage(filePath)) && (bool)splitViewerTool?.GetCPDFViewer()?.SetStampMouseImage(filePath))
  298. {
  299. return true;
  300. }
  301. return false;
  302. }
  303. public void SetIsVisibleCustomMouse(bool isVisbleCustomMouse)
  304. {
  305. viewerTool?.GetCPDFViewer()?.SetIsVisibleCustomMouse(isVisbleCustomMouse);
  306. splitViewerTool?.GetCPDFViewer()?.SetIsVisibleCustomMouse(isVisbleCustomMouse);
  307. }
  308. public CPDFViewer GetCPDFViewer()
  309. {
  310. return FocusPDFViewTool?.GetCPDFViewer();
  311. }
  312. public BaseWidget GetCacheHitTestWidget()
  313. {
  314. return FocusPDFViewTool?.GetCacheHitTestWidget();
  315. }
  316. public BaseAnnot GetCacheHitTestAnnot()
  317. {
  318. return FocusPDFViewTool?.GetCacheHitTestAnnot();
  319. }
  320. public void CreateViewerMenu(object sender, ref ContextMenu contextMenu)
  321. {
  322. MenuItem fitWidthMenu = new MenuItem();
  323. fitWidthMenu.Header = LanguageHelper.CommonManager.GetString("Menu_AutoSize");
  324. fitWidthMenu.Click += (o, p) =>
  325. {
  326. FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitWidth);
  327. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  328. };
  329. contextMenu.Items.Add(fitWidthMenu);
  330. MenuItem fitSizeMenu = new MenuItem();
  331. fitSizeMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RealSize");
  332. fitSizeMenu.Click += (o, p) =>
  333. {
  334. FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitOriginal);
  335. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  336. };
  337. contextMenu.Items.Add(fitSizeMenu);
  338. MenuItem zoomInMenu = new MenuItem();
  339. zoomInMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomIn");
  340. zoomInMenu.Click += (o, p) =>
  341. {
  342. FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitZoom);
  343. double zoom = FocusPDFViewTool?.GetCPDFViewer()?.GetZoom() ?? 1;
  344. FocusPDFViewTool?.GetCPDFViewer()?.SetZoom(CheckZoomLevel(zoom, true));
  345. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  346. };
  347. contextMenu.Items.Add(zoomInMenu);
  348. MenuItem zoomOutMenu = new MenuItem();
  349. zoomOutMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomOut");
  350. zoomOutMenu.Click += (o, p) =>
  351. {
  352. FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitZoom);
  353. double zoom = FocusPDFViewTool?.GetCPDFViewer()?.GetZoom() ?? 1;
  354. FocusPDFViewTool?.GetCPDFViewer()?.SetZoom(CheckZoomLevel(zoom, false));
  355. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  356. };
  357. contextMenu.Items.Add(zoomOutMenu);
  358. contextMenu.Items.Add(new Separator());
  359. MenuItem singleView = new MenuItem();
  360. singleView.Header = LanguageHelper.CommonManager.GetString("Menu_SinglePage");
  361. singleView.Click += (o, p) =>
  362. {
  363. FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.Single);
  364. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  365. };
  366. contextMenu.Items.Add(singleView);
  367. MenuItem singleContinuousView = new MenuItem();
  368. singleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_SingleContinuous");
  369. singleContinuousView.Click += (o, p) =>
  370. {
  371. FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.SingleContinuous);
  372. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  373. };
  374. contextMenu.Items.Add(singleContinuousView);
  375. MenuItem doubleView = new MenuItem();
  376. doubleView.Header = LanguageHelper.CommonManager.GetString("Menu_DoublePage");
  377. doubleView.Click += (o, p) =>
  378. {
  379. FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.Double);
  380. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  381. };
  382. contextMenu.Items.Add(doubleView);
  383. MenuItem doubleContinuousView = new MenuItem();
  384. doubleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_DoubleContinuous");
  385. doubleContinuousView.Click += (o, p) =>
  386. {
  387. FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.DoubleContinuous);
  388. FocusPDFViewTool?.GetCPDFViewer()?.UpdateRenderFrame();
  389. };
  390. contextMenu.Items.Add(doubleContinuousView);
  391. contextMenu.Items.Add(new Separator());
  392. MenuItem resetFormMenu = new MenuItem();
  393. resetFormMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Reset");
  394. resetFormMenu.Click += (o, p) =>
  395. {
  396. //FocusPDFViewTool?.GetCPDFViewer()?.ResetForm();
  397. };
  398. contextMenu.Items.Add(resetFormMenu);
  399. }
  400. private void RemoveSplitViewerTool()
  401. {
  402. UpdateRenderFrame();
  403. VerticalSplitter.Visibility = Visibility.Collapsed;
  404. HorizontalSplitter.Visibility = Visibility.Collapsed;
  405. VerticalView.Visibility = Visibility.Collapsed;
  406. HorizontalView.Visibility = Visibility.Collapsed;
  407. ViewToolGrid.ColumnDefinitions[1].Width = new GridLength(0);
  408. ViewToolGrid.ColumnDefinitions[2].Width = new GridLength(0);
  409. ViewToolGrid.RowDefinitions[1].Height = new GridLength(0);
  410. ViewToolGrid.RowDefinitions[2].Height = new GridLength(0);
  411. VerticalView.Child = null;
  412. HorizontalView.Child = null;
  413. }
  414. public void WindowSizeChange()
  415. {
  416. if(VerticalView.Visibility == Visibility.Visible)
  417. {
  418. ViewToolGrid.ColumnDefinitions[2].Width = new GridLength(ViewToolGrid.ActualWidth * splitWidthScale);
  419. }
  420. if(HorizontalView.Visibility == Visibility.Visible)
  421. {
  422. ViewToolGrid.RowDefinitions[2].Height = new GridLength(ViewToolGrid.ActualHeight * splitHeightScale);
  423. }
  424. }
  425. private void PDFView_GotFocus(object sender, RoutedEventArgs e)
  426. {
  427. switch ((sender as Border).Tag)
  428. {
  429. case "ViewerTool":
  430. FocusPDFViewTool = viewerTool;
  431. break;
  432. case "SplitViewerTool":
  433. FocusPDFViewTool = splitViewerTool;
  434. break;
  435. }
  436. if (FocusPDFViewTool.IsLoaded)
  437. {
  438. FocusPDFViewToolChanged?.Invoke(this, EventArgs.Empty);
  439. }
  440. }
  441. #region Private Command Methods
  442. private double CheckZoomLevel(double zoom, bool IsGrowth)
  443. {
  444. zoom += (IsGrowth ? 0.01 : -0.01);
  445. double standardZoom = 100;
  446. if (zoom <= 0.01)
  447. {
  448. return 0.01;
  449. }
  450. if (zoom >= 10)
  451. {
  452. return 10;
  453. }
  454. zoom *= 100;
  455. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  456. {
  457. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  458. {
  459. standardZoom = zoomLevelList[i + 1];
  460. break;
  461. }
  462. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  463. {
  464. standardZoom = zoomLevelList[i];
  465. break;
  466. }
  467. }
  468. return standardZoom / 100;
  469. }
  470. #endregion
  471. private void PDFView_MouseDown(object sender, MouseButtonEventArgs e)
  472. {
  473. switch ((sender as Border).Tag)
  474. {
  475. case "ViewerTool":
  476. FocusPDFViewTool = viewerTool;
  477. break;
  478. case "SplitViewerTool":
  479. FocusPDFViewTool = splitViewerTool;
  480. break;
  481. }
  482. if (FocusPDFViewTool.IsLoaded&& FocusPDFViewTool.GetCPDFViewer()?.CurrentRenderFrame != null)
  483. {
  484. FocusPDFViewToolChanged?.Invoke(this, EventArgs.Empty);
  485. }
  486. }
  487. }
  488. }