BottomToolContentViewModel.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. using Prism.Mvvm;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using ComPDFKitViewer.PdfViewer;
  8. using Prism.Commands;
  9. using Prism.Regions;
  10. using System.Windows;
  11. using PDF_Master.Views;
  12. using ComPDFKitViewer;
  13. using System.Windows.Input;
  14. using System.Windows.Controls;
  15. using Prism.Services.Dialogs;
  16. using PDF_Master.CustomControl;
  17. using PDF_Master.Model;
  18. using PDF_Master.ViewModels.BOTA;
  19. using PDF_Master.Views.BOTA;
  20. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  21. using PDF_Master.Views.Tools;
  22. using PDFSettings;
  23. using PDF_Master.Helper;
  24. using System.IO;
  25. using ImTools;
  26. using PDF_Master.Views.PropertyPanel.ViewModular;
  27. namespace PDF_Master.ViewModels
  28. {
  29. public class BottomToolContentViewModel : BindableBase, INavigationAware
  30. {
  31. #region 文案
  32. private string T_actual;
  33. public string T_Actual
  34. {
  35. get { return T_actual; }
  36. set
  37. {
  38. SetProperty(ref T_actual, value);
  39. }
  40. }
  41. private string T_fitWidth;
  42. public string T_FitWidth
  43. {
  44. get { return T_fitWidth; }
  45. set
  46. {
  47. SetProperty(ref T_fitWidth, value);
  48. }
  49. }
  50. private string T_fitPage;
  51. public string T_FitPage
  52. {
  53. get { return T_fitPage; }
  54. set
  55. {
  56. SetProperty(ref T_fitPage, value);
  57. }
  58. }
  59. private string T_continuousText;
  60. public string T_ContinuousText
  61. {
  62. get { return T_continuousText; }
  63. set
  64. {
  65. SetProperty(ref T_continuousText, value);
  66. }
  67. }
  68. private string T_continuousTip;
  69. public string T_ContinuousTip
  70. {
  71. get { return T_continuousTip; }
  72. set
  73. {
  74. SetProperty(ref T_continuousTip, value);
  75. }
  76. }
  77. private string T_singlePageText;
  78. public string T_SinglePageText
  79. {
  80. get { return T_singlePageText; }
  81. set
  82. {
  83. SetProperty(ref T_singlePageText, value);
  84. }
  85. }
  86. private string T_singlePageTip;
  87. public string T_SinglePageTip
  88. {
  89. get { return T_singlePageTip; }
  90. set
  91. {
  92. SetProperty(ref T_singlePageTip, value);
  93. }
  94. }
  95. private string T_facingText;
  96. public string T_FacingText
  97. {
  98. get { return T_facingText; }
  99. set
  100. {
  101. SetProperty(ref T_facingText, value);
  102. }
  103. }
  104. private string T_facingTip;
  105. public string T_FacingTip
  106. {
  107. get { return T_facingTip; }
  108. set
  109. {
  110. SetProperty(ref T_facingTip, value);
  111. }
  112. }
  113. private string T_bookModeTip;
  114. public string T_BookModeTip
  115. {
  116. get { return T_bookModeTip; }
  117. set
  118. {
  119. SetProperty(ref T_bookModeTip, value);
  120. }
  121. }
  122. private string T_bookModeText;
  123. public string T_BookModeText
  124. {
  125. get { return T_bookModeText; }
  126. set
  127. {
  128. SetProperty(ref T_bookModeText, value);
  129. }
  130. }
  131. //private string T_showViewModularTip;
  132. //public string T_ShowViewModularTip
  133. //{
  134. // get { return T_showViewModularTip; }
  135. // set
  136. // {
  137. // SetProperty(ref T_showViewModularTip, value);
  138. // }
  139. //}
  140. private string T_showViewModularText;
  141. public string T_ShowViewModularText
  142. {
  143. get { return T_showViewModularText; }
  144. set
  145. {
  146. SetProperty(ref T_showViewModularText, value);
  147. }
  148. }
  149. private void InitString()
  150. {
  151. T_Actual = App.MainPageLoader.GetString("Zoom_Actual");
  152. T_FitWidth = App.MainPageLoader.GetString("Zoom_FitWidth");
  153. T_FitPage = App.MainPageLoader.GetString("Zoom_FitPage");
  154. T_ContinuousText = App.MainPageLoader.GetString("MainPage_Continuous");
  155. T_ContinuousTip = App.MainPageLoader.GetString("MainPage_ViewPageContinousTip");
  156. T_SinglePageText = App.MainPageLoader.GetString("MainPage_SinglePage");
  157. T_SinglePageTip = App.MainPageLoader.GetString("MainPage_SinglePageTip");
  158. T_FacingText = App.MainPageLoader.GetString("MainPage_Facing");
  159. T_FacingTip = App.MainPageLoader.GetString("MainPage_FacingTip");
  160. T_BookModeText = App.MainPageLoader.GetString("MainPage_BookMode");
  161. T_BookModeTip = App.MainPageLoader.GetString("MainPage_BookModeTip");
  162. T_ShowViewModularText = App.MainPageLoader.GetString("MainPage_ShowViewModular");
  163. //T_ShowViewModularTip = App.MainPageLoader.GetString("MainPage_ShowViewModularTip");
  164. }
  165. #endregion 文案
  166. public DelegateCommand Load { get; set; }
  167. public DelegateCommand FirstPageCommand { get; set; }
  168. public DelegateCommand LastPageCommand { get; set; }
  169. public DelegateCommand PrePageCommand { get; set; }
  170. public DelegateCommand NextPageCommand { get; set; }
  171. public DelegateCommand MyPropertyCommand { get; set; }
  172. public DelegateCommand FullScreenCommand { get; set; }
  173. public DelegateCommand ReadModeCommand { get; set; }
  174. public DelegateCommand OpenViewCommand { get; set; }
  175. public DelegateCommand ZoomInCommand { get; set; }
  176. public DelegateCommand ZoomOutCommand { get; set; }
  177. public DelegateCommand SetViewModeCommand { get; set; }
  178. public DelegateCommand OpenFullCommand { get; set; }
  179. public DelegateCommand<object> PageTextKeyDownCommand { get; set; }
  180. public DelegateCommand<object> PageTextPreviewKeyDownCommand { get; set; }
  181. public DelegateCommand<object> SelectionChangedCommand { get; set; }
  182. public DelegateCommand<object> ShowViewModularCommand { get; set; }
  183. /// <summary>
  184. /// 上一个视图
  185. /// </summary>
  186. public DelegateCommand PreViewCommand { get; set; }
  187. /// <summary>
  188. /// 下一个视图
  189. /// </summary>
  190. public DelegateCommand NextViewCommnad { get; set; }
  191. /// <summary>
  192. /// 拦截键盘输入的事件
  193. /// </summary>
  194. public DelegateCommand<object> PreviewKeyDown { get; set; }
  195. /// <summary>
  196. /// 进入单页
  197. /// </summary>
  198. public DelegateCommand SinglePageCommand { get; set; }
  199. /// <summary>
  200. /// 进入双页
  201. /// </summary>
  202. public DelegateCommand DoublePageCommand { get; set; }
  203. /// <summary>
  204. /// 回到实际大小
  205. /// </summary>
  206. public DelegateCommand RealSizeCommand { get; set; }
  207. private bool isShowViewModular = false;
  208. /// <summary>
  209. /// 是否已经显示 用于跳过控件显示前触发的事件
  210. /// </summary>
  211. public bool IsLoaded = false;
  212. /// <summary>
  213. /// 属性栏是否展开
  214. /// </summary>
  215. public bool IsShowViewModular
  216. {
  217. get { return isShowViewModular; }
  218. set
  219. {
  220. SetProperty(ref isShowViewModular, value);
  221. }
  222. }
  223. private bool isSingleView;
  224. public bool IsSingleView
  225. {
  226. get { return isSingleView; }
  227. set
  228. {
  229. SetProperty(ref isSingleView, value);
  230. if (value)
  231. {
  232. SetModeView();
  233. }
  234. }
  235. }
  236. private bool isContinue;
  237. public bool IsContinue
  238. {
  239. get { return isContinue; }
  240. set
  241. {
  242. SetProperty(ref isContinue, value);
  243. SetModeView();
  244. }
  245. }
  246. private bool isDoubleView;
  247. public bool IsDoubleView
  248. {
  249. get { return isDoubleView; }
  250. set
  251. {
  252. SetProperty(ref isDoubleView, value);
  253. if (value)
  254. {
  255. SetModeView();
  256. }
  257. }
  258. }
  259. private bool isBookMode;
  260. public bool IsBookMode
  261. {
  262. get { return isBookMode; }
  263. set
  264. {
  265. SetProperty(ref isBookMode, value);
  266. if (value)
  267. {
  268. SetModeView();
  269. }
  270. }
  271. }
  272. private int pageCount;
  273. public int PageCount
  274. {
  275. get { return pageCount; }
  276. set
  277. {
  278. SetProperty(ref pageCount, value);
  279. }
  280. }
  281. private int currentPage;
  282. public int CurrentPage
  283. {
  284. get { return currentPage; }
  285. set
  286. {
  287. SetProperty(ref currentPage, value);
  288. }
  289. }
  290. private double currenZoom;
  291. public double CurrentZoom
  292. {
  293. get { return currenZoom; }
  294. set { SetProperty(ref currenZoom, value); }
  295. }
  296. private int selectedIndex;
  297. public int SelectedIndex
  298. {
  299. get { return selectedIndex; }
  300. set
  301. {
  302. SetProperty(ref selectedIndex, value);
  303. }
  304. }
  305. private bool rightPanelEnable = true;
  306. public bool RightPanelEnable
  307. {
  308. get { return rightPanelEnable; }
  309. set
  310. {
  311. SetProperty(ref rightPanelEnable, value);
  312. }
  313. }
  314. private bool isPreEnable = false;
  315. /// <summary>
  316. /// 前进是否启用
  317. /// </summary>
  318. public bool IsPreEnable
  319. {
  320. get { return isPreEnable; }
  321. set
  322. {
  323. SetProperty(ref isPreEnable, value);
  324. }
  325. }
  326. private bool isNextEnable = false;
  327. public bool IsNextEnable
  328. {
  329. get { return isNextEnable; }
  330. set
  331. {
  332. SetProperty(ref isNextEnable, value);
  333. }
  334. }
  335. private Stack<int> UndoStack = new Stack<int>();
  336. private Stack<int> RedoStack = new Stack<int>();
  337. public CPDFViewer PDFViewer { get; set; }
  338. public ViewContentViewModel ViewContentViewModel { get; set; }
  339. public OpenFileInfo OpenFileInfo = null;
  340. /// <summary>
  341. /// 来自undo redo方法的跳页 不计入栈
  342. /// </summary>
  343. private bool isFromMethod = false;
  344. /// <summary>
  345. /// 记录上一个页面索引值
  346. /// </summary>
  347. private int oldPageIndex = 0;
  348. /// <summary>
  349. /// 上下滑动的固定值
  350. /// </summary>
  351. private double scrolloffset = 50;
  352. private IRegionManager region;
  353. private IDialogService dialogs;
  354. public BottomToolContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  355. {
  356. region = regionManager;
  357. dialogs = dialogService;
  358. PrePageCommand = new DelegateCommand(GoPrePage, CanPrePageExcute).ObservesProperty(() => CurrentPage);
  359. NextPageCommand = new DelegateCommand(GoNextPage, CanNextPageExcute).ObservesProperty(() => CurrentPage);
  360. FirstPageCommand = new DelegateCommand(GoFirstPage, CanPrePageExcute).ObservesProperty(() => CurrentPage);
  361. LastPageCommand = new DelegateCommand(GoLastPage, CanNextPageExcute).ObservesProperty(() => CurrentPage);
  362. ZoomInCommand = new DelegateCommand(ZoomIn, CanZoomIn).ObservesProperty(() => CurrentZoom);
  363. ZoomOutCommand = new DelegateCommand(ZoomOut, CanZoomOut).ObservesProperty(() => CurrentZoom);
  364. SetViewModeCommand = new DelegateCommand(SetModeView);
  365. PageTextKeyDownCommand = new DelegateCommand<object>(PageNumText_KeyDown);
  366. PageTextPreviewKeyDownCommand = new DelegateCommand<object>(PageNumText_PreviewKeyDown);
  367. SelectionChangedCommand = new DelegateCommand<object>(SelectionChangedEvent);
  368. ShowViewModularCommand = new DelegateCommand<object>(ShowViewModularEvent);
  369. PreviewKeyDown = new DelegateCommand<object>(previewkeydown);
  370. PreViewCommand = new DelegateCommand(undo);
  371. SinglePageCommand = new DelegateCommand(() => { IsSingleView = true; });
  372. DoublePageCommand = new DelegateCommand(() => { IsDoubleView = true; });
  373. RealSizeCommand = new DelegateCommand(ZoomToRealSize);
  374. NextViewCommnad = new DelegateCommand(redo);
  375. InitString();
  376. }
  377. /// <summary>
  378. /// 缩放至实际大小
  379. /// </summary>
  380. private void ZoomToRealSize()
  381. {
  382. PDFViewer?.ChangeFitMode(FitMode.FitSize);
  383. if (OpenFileInfo != null)
  384. {
  385. OpenFileInfo.LastFitMode = FitMode.FitSize;
  386. }
  387. }
  388. private void previewkeydown(object e)
  389. {
  390. var args = e as KeyEventArgs;
  391. if (args == null)
  392. {
  393. return;
  394. }
  395. //输入值的预处理通过input事件里写正则来判断
  396. if (args.Key == Key.Enter)
  397. {
  398. var text = (args.OriginalSource as TextBox);
  399. int zoom = int.Parse(text.Text.Replace("%", ""));
  400. PDFViewer?.Zoom(zoom / 100.0);
  401. }
  402. }
  403. private void undo()
  404. {
  405. if (!IsPreEnable)
  406. {
  407. return;
  408. }
  409. RedoStack.Push(PDFViewer.CurrentIndex);
  410. IsNextEnable = true;
  411. App.Current.Dispatcher.Invoke(() =>
  412. {
  413. int index = UndoStack.Pop();
  414. PDFViewer.GoToPage(index);
  415. if (UndoStack.Count <= 0)
  416. {
  417. IsPreEnable = false;
  418. }
  419. });
  420. isFromMethod = true;
  421. }
  422. private void redo()
  423. {
  424. if (!IsNextEnable)
  425. {
  426. return;
  427. }
  428. App.Current.Dispatcher.Invoke(() =>
  429. {
  430. UndoStack.Push(PDFViewer.CurrentIndex);
  431. IsPreEnable = true;
  432. int index = RedoStack.Pop();
  433. PDFViewer.GoToPage(index);
  434. if (RedoStack.Count <= 0)
  435. {
  436. IsNextEnable = false;
  437. }
  438. });
  439. isFromMethod = true;
  440. }
  441. private void ShowViewModularEvent(object obj)
  442. {
  443. if (region.Regions.ContainsRegionWithName(ViewContentViewModel.PropertyRegionName))
  444. {
  445. var check = (bool)obj;
  446. if (check)
  447. {
  448. ViewContentViewModel.IsPropertyOpen = true;
  449. NavigationParameters param = new NavigationParameters();
  450. param.Add(ParameterNames.PDFViewer, PDFViewer);
  451. param.Add(ParameterNames.BottomToolContentViewModel, this);
  452. region.RequestNavigate(RegionNames.PropertyRegionName, "ViewModularContent", param);
  453. }
  454. else
  455. {
  456. ViewContentViewModel.IsPropertyOpen = false;
  457. region.RequestNavigate(RegionNames.PropertyRegionName, "PropertyPanelContent");
  458. }
  459. }
  460. }
  461. private void SelectionChangedEvent(object e)
  462. {
  463. if (e == null)
  464. {
  465. return;
  466. }
  467. var args = e as SelectionChangedEventArgs;
  468. if (args != null)
  469. {
  470. if (SelectedIndex <= 2)
  471. {
  472. switch (SelectedIndex)
  473. {
  474. case 0:
  475. PDFViewer?.ChangeFitMode(FitMode.FitSize);
  476. if (OpenFileInfo != null)
  477. {
  478. OpenFileInfo.LastFitMode = FitMode.FitSize;
  479. }
  480. break;
  481. case 1:
  482. PDFViewer?.ChangeFitMode(FitMode.FitWidth);
  483. if (OpenFileInfo != null)
  484. {
  485. OpenFileInfo.LastFitMode = FitMode.FitWidth;
  486. }
  487. break;
  488. case 2:
  489. PDFViewer?.ChangeFitMode(FitMode.FitHeight);
  490. if (OpenFileInfo != null)
  491. {
  492. OpenFileInfo.LastFitMode = FitMode.FitHeight;
  493. }
  494. break;
  495. default:
  496. break;
  497. }
  498. }
  499. else
  500. {
  501. if (args.AddedItems[0] is ComboBoxItem)
  502. {
  503. if ((args.AddedItems[0] as ComboBoxItem).Tag != null)
  504. {
  505. PDFViewer?.Zoom(Convert.ToDouble((args.AddedItems[0] as ComboBoxItem).Tag.ToString()) / 100.0);
  506. }
  507. }
  508. }
  509. }
  510. }
  511. private void PageNumText_PreviewKeyDown(object e)
  512. {
  513. var args = e as KeyEventArgs;
  514. if (args != null)
  515. {
  516. //显示文本框输入内容
  517. List<Key> NumberKeys = new List<Key>() { Key.D0,Key.D1,Key.D2,Key.D3,Key.D4,Key.D5,Key.D6,Key.D7,Key.D8,Key.D9,Key.NumPad0,Key.NumPad1,Key.NumPad2,
  518. Key.NumPad3,Key.NumPad4,Key.NumPad5,Key.NumPad6,Key.NumPad7,Key.NumPad8,Key.NumPad9,Key.Delete,Key.Back,Key.Enter,Key.Right,Key.Left};
  519. if (!NumberKeys.Contains(args.Key))
  520. {
  521. args.Handled = true;
  522. }
  523. }
  524. }
  525. private void PageNumText_KeyDown(object e)
  526. {
  527. if (!(e is KeyEventArgs))
  528. return;
  529. //回车提交输入
  530. if ((e as KeyEventArgs).Key == System.Windows.Input.Key.Enter)
  531. {
  532. int pagenum = 0;
  533. string text = ((e as KeyEventArgs).OriginalSource as TextBox).Text.ToString();
  534. char[] chs = { ' ', '/', '\\' };//字符截取 拒止非法输入
  535. int i = text.LastIndexOfAny(chs);
  536. if (i > 0)
  537. text = text.Substring(0, i - 1);
  538. if (!int.TryParse(text, out pagenum))
  539. {
  540. CurrentPage = PDFViewer.Document.PageCount;
  541. ((e as KeyEventArgs).OriginalSource as TextBox).Text = PDFViewer.Document.PageCount.ToString();
  542. return;
  543. }
  544. if (pagenum < 1)
  545. pagenum = 1;
  546. else if (pagenum > PDFViewer.Document.PageCount)
  547. pagenum = PDFViewer.Document.PageCount;
  548. PDFViewer.GoToPage(pagenum - 1);
  549. CurrentPage = pagenum;
  550. ((e as KeyEventArgs).OriginalSource as TextBox).Text = pagenum.ToString();
  551. }
  552. }
  553. private void GoPrePage()
  554. {
  555. if (PDFViewer != null)
  556. {
  557. if (PDFViewer.RenderPageStart == PDFViewer.CurrentIndex)
  558. {
  559. PDFViewer.GoToPage(PDFViewer.CurrentIndex - 1);
  560. }
  561. else
  562. {
  563. if ((PDFViewer.RenderPageStart - 1) > 0)
  564. {
  565. PDFViewer.GoToPage(PDFViewer.RenderPageStart - 1);
  566. }
  567. else
  568. {
  569. PDFViewer.GoToPage(PDFViewer.CurrentIndex - 1);
  570. }
  571. }
  572. }
  573. }
  574. private bool CanPrePageExcute()
  575. {
  576. if (PDFViewer != null)
  577. {
  578. if (PDFViewer.CurrentIndex <= 0)
  579. return false;
  580. else
  581. return true;
  582. }
  583. return false;
  584. }
  585. private void GoNextPage()
  586. {
  587. if (PDFViewer != null)
  588. {
  589. PDFViewer.GoToPage(PDFViewer.CurrentIndex + 1);
  590. //双页模式 一次性跳两页
  591. if (((int)PDFViewer.ModeView > 2))
  592. {
  593. PDFViewer.GoToPage(PDFViewer.CurrentIndex + 2);
  594. }
  595. }
  596. }
  597. private bool CanNextPageExcute()
  598. {
  599. if (PDFViewer != null)
  600. {
  601. if (CurrentPage >= PDFViewer.Document.PageCount)
  602. return false;
  603. else
  604. return true;
  605. }
  606. return false;
  607. }
  608. private void GoFirstPage()
  609. {
  610. if (PDFViewer != null)
  611. {
  612. PDFViewer.GoToPage(0);
  613. }
  614. }
  615. private void GoLastPage()
  616. {
  617. if (PDFViewer != null)
  618. {
  619. PDFViewer.GoToPage(PDFViewer.Document.PageCount - 1);
  620. }
  621. }
  622. private void ZoomIn()
  623. {
  624. double zoom = SetPageZoomFactor(true);
  625. PDFViewer.Zoom(zoom / 100);
  626. }
  627. private void ZoomOut()
  628. {
  629. double zoom = SetPageZoomFactor(false);
  630. PDFViewer.Zoom(zoom / 100);
  631. }
  632. private double SetPageZoomFactor(bool flag)
  633. {
  634. double zoom = PDFViewer.ZoomFactor * 100;
  635. if (flag)
  636. {
  637. if (zoom >= 25 && zoom <= 300)
  638. {
  639. zoom = zoom + 25;
  640. }
  641. else if (zoom >= 301 && zoom <= 1000)
  642. {
  643. zoom = zoom + 40;
  644. }
  645. else if (zoom >= 1001 && zoom <= 10000)
  646. {
  647. zoom = zoom + 100;
  648. }
  649. }
  650. else
  651. {
  652. if (zoom >= 25 && zoom <= 300)
  653. {
  654. zoom = zoom - 25;
  655. }
  656. else if (zoom >= 301 && zoom <= 1000)
  657. {
  658. zoom = zoom - 40;
  659. }
  660. else if (zoom >= 1001 && zoom <= 10000)
  661. {
  662. zoom = zoom - 100;
  663. }
  664. }
  665. if (zoom < 25)
  666. {
  667. zoom = 25;
  668. }
  669. if (zoom > 10000)
  670. {
  671. zoom = 10000;
  672. }
  673. return zoom;
  674. }
  675. private bool CanZoomIn()
  676. {
  677. if (PDFViewer != null)
  678. {
  679. if (PDFViewer.ZoomFactor * 100 >= 10000)
  680. return false;
  681. else
  682. return true;
  683. }
  684. return false;
  685. }
  686. private bool CanZoomOut()
  687. {
  688. if (PDFViewer != null)
  689. {
  690. if (PDFViewer.ZoomFactor * 100 <= 25)
  691. return false;
  692. else
  693. return true;
  694. }
  695. return false;
  696. }
  697. public void PDFViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  698. {
  699. if (e.Key == "PageNum")
  700. {
  701. RenderData renderData = e.Value as RenderData;
  702. if (renderData != null)
  703. {
  704. CurrentPage = renderData.PageIndex;
  705. PageCount = PDFViewer.Document.PageCount;
  706. if (!renderData.IsMouseWheel && !isFromMethod)
  707. {
  708. UndoStack.Push(oldPageIndex);
  709. RedoStack.Clear();
  710. IsNextEnable = false;
  711. IsPreEnable = true;
  712. }
  713. isFromMethod = false;
  714. }
  715. oldPageIndex = renderData.PageIndex - 1;
  716. }
  717. if (e.Key == "ViewMode")
  718. {
  719. GetModeView((ViewMode)e.Value);
  720. }
  721. if (e.Key == "Zoom")
  722. {
  723. CurrentZoom = (double)e.Value * 100;
  724. switch (PDFViewer.ModeFit)
  725. {
  726. case FitMode.FitWidth:
  727. SelectedIndex = 1;
  728. break;
  729. case FitMode.FitHeight:
  730. SelectedIndex = 2;
  731. break;
  732. case FitMode.FitSize:
  733. SelectedIndex = 0;
  734. break;
  735. case FitMode.FitFree:
  736. SelectedIndex = -1;
  737. break;
  738. default:
  739. break;
  740. }
  741. }
  742. if (OpenFileInfo != null)
  743. {
  744. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  745. {
  746. OpenFileInfo.LastFitMode = PDFViewer.ModeFit;
  747. }
  748. if (PDFViewer.ModeFit == FitMode.FitFree)
  749. {
  750. if (OpenFileInfo.LastZoom != PDFViewer.ZoomFactor)
  751. {
  752. OpenFileInfo.LastZoom = PDFViewer.ZoomFactor;
  753. }
  754. }
  755. if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
  756. {
  757. OpenFileInfo.LastPageIndex = PDFViewer.CurrentIndex;
  758. }
  759. SettingHelper.SetFileInfo(OpenFileInfo);
  760. }
  761. }
  762. private void ViewContentViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  763. {
  764. if (e.PropertyName == "OCRContentVisible")
  765. {
  766. if (ViewContentViewModel.OCRContentVisible == Visibility.Visible)
  767. {
  768. RightPanelEnable = false;
  769. }
  770. else
  771. {
  772. RightPanelEnable = true;
  773. }
  774. }
  775. if (e.PropertyName == "IsPropertyOpen")
  776. {
  777. //右上角按钮收起属性面板后,底部工具栏按钮状态同步变化
  778. if (ViewContentViewModel.IsPropertyOpen == false)
  779. {
  780. //监听的属性面板的变化
  781. IsShowViewModular = ViewContentViewModel.IsPropertyOpen;
  782. }
  783. }
  784. }
  785. /// <summary>
  786. /// 设置缩放控件的选中项
  787. /// </summary>
  788. private void SetZoomIndex()
  789. {
  790. switch (PDFViewer.ModeFit)
  791. {
  792. case FitMode.FitWidth:
  793. SelectedIndex = 1;
  794. break;
  795. case FitMode.FitHeight:
  796. SelectedIndex = 2;
  797. break;
  798. case FitMode.FitSize:
  799. SelectedIndex = 0;
  800. break;
  801. case FitMode.FitFree:
  802. SelectedIndex = -1;
  803. break;
  804. default:
  805. break;
  806. }
  807. }
  808. private void GetModeView(ViewMode mode)
  809. {
  810. if ((int)mode % 2 == 0)
  811. {
  812. if (!IsContinue)
  813. {
  814. IsContinue = true;
  815. }
  816. }
  817. else
  818. {
  819. if (IsContinue)
  820. {
  821. IsContinue = false;
  822. }
  823. }
  824. if ((int)mode <= 2)
  825. {
  826. if (!isSingleView)
  827. {
  828. IsSingleView = true;
  829. }
  830. }
  831. else if ((int)mode <= 4)
  832. {
  833. if (!isDoubleView)
  834. {
  835. IsDoubleView = true;
  836. }
  837. }
  838. else
  839. {
  840. if (!isBookMode)
  841. {
  842. IsBookMode = true;
  843. }
  844. }
  845. }
  846. public void SetModeView()
  847. {
  848. if (PDFViewer != null)
  849. {
  850. if (IsContinue)
  851. {
  852. if (IsSingleView)
  853. {
  854. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  855. }
  856. else if (IsDoubleView)
  857. {
  858. PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
  859. }
  860. else
  861. {
  862. PDFViewer.ChangeViewMode(ViewMode.BookContinuous);
  863. }
  864. }
  865. else
  866. {
  867. if (IsSingleView)
  868. {
  869. PDFViewer.ChangeViewMode(ViewMode.Single);
  870. }
  871. else if (IsDoubleView)
  872. {
  873. PDFViewer.ChangeViewMode(ViewMode.Double);
  874. }
  875. else
  876. {
  877. PDFViewer.ChangeViewMode(ViewMode.Book);
  878. }
  879. }
  880. }
  881. SaveMode(PDFViewer.ModeView);
  882. }
  883. private void SaveMode(object modeView)
  884. {
  885. OpenFileInfo fileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  886. if (fileInfo != null)
  887. {
  888. if (modeView is SplitMode)
  889. {
  890. fileInfo.LastSplitMode = PDFViewer.Mode;
  891. }
  892. else if (modeView is ViewMode)
  893. {
  894. fileInfo.LastViewMode = PDFViewer.ModeView;
  895. }
  896. else if (modeView is bool)
  897. {
  898. fileInfo.LastPageSpace = (bool)modeView;
  899. }
  900. SettingHelper.SetFileInfo(fileInfo);
  901. }
  902. }
  903. #region Navigation
  904. public void OnNavigatedTo(NavigationContext navigationContext)
  905. {
  906. var viewContentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  907. if (viewContentViewModel != null)
  908. {
  909. this.ViewContentViewModel = viewContentViewModel;
  910. ViewContentViewModel.bottom = this;
  911. IsShowViewModular = viewContentViewModel.IsPropertyOpen;
  912. viewContentViewModel.PropertyChanged -= ViewContentViewModel_PropertyChanged;
  913. viewContentViewModel.PropertyChanged += ViewContentViewModel_PropertyChanged;
  914. }
  915. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  916. if (pdfview != null)
  917. {
  918. if (ViewContentViewModel.OpenFileInfo != null)
  919. {
  920. OpenFileInfo = ViewContentViewModel.OpenFileInfo;
  921. }
  922. //获取页面设置等信息
  923. PDFViewer = pdfview;
  924. oldPageIndex = pdfview.CurrentIndex;
  925. PageCount = PDFViewer.Document.PageCount;
  926. GetModeView(PDFViewer.ModeView);
  927. //设置下拉框选中项
  928. SetZoomIndex();
  929. if (PageCount > 0)
  930. {
  931. //文档解密后再获取当前页,以此来确保上下翻页按钮的状态的准确的
  932. CurrentPage = PDFViewer.CurrentIndex + 1;
  933. }
  934. CurrentZoom = PDFViewer.ZoomFactor * 100;
  935. PDFViewer.InfoChanged += PDFViewer_InfoChanged;
  936. }
  937. }
  938. public bool IsNavigationTarget(NavigationContext navigationContext)
  939. {
  940. return true;
  941. }
  942. public void OnNavigatedFrom(NavigationContext navigationContext)
  943. {
  944. IsShowViewModular = ViewContentViewModel.IsPropertyOpen;
  945. }
  946. #endregion Navigation
  947. }
  948. }