ViewModularContentViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.PdfViewer;
  3. using Microsoft.Office.Interop.Word;
  4. using PDF_Office.CustomControl;
  5. using PDF_Office.Helper;
  6. using PDF_Office.Model;
  7. using PDF_Office.ViewModels.BOTA;
  8. using PDF_Office.Views;
  9. using PDFSettings.Settings;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using Prism.Regions;
  13. using Prism.Services.Dialogs;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. using System.Windows.Forms;
  21. namespace PDF_Office.ViewModels.PropertyPanel.ViewModular
  22. {
  23. public class ViewModularContentViewModel : BindableBase, INavigationAware
  24. {
  25. #region 文案
  26. private string T_title;
  27. public string T_Title
  28. {
  29. get { return T_title; }
  30. set
  31. {
  32. SetProperty(ref T_title, value);
  33. }
  34. }
  35. private string T_modeTitle;
  36. public string T_ModeTitle
  37. {
  38. get { return T_modeTitle; }
  39. set
  40. {
  41. SetProperty(ref T_modeTitle, value);
  42. }
  43. }
  44. private string T_single;
  45. public string T_Single
  46. {
  47. get { return T_single; }
  48. set
  49. {
  50. SetProperty(ref T_single, value);
  51. }
  52. }
  53. private string T_two;
  54. public string T_Two
  55. {
  56. get { return T_two; }
  57. set
  58. {
  59. SetProperty(ref T_two, value);
  60. }
  61. }
  62. private string T_book;
  63. public string T_Book
  64. {
  65. get { return T_book; }
  66. set
  67. {
  68. SetProperty(ref T_book, value);
  69. }
  70. }
  71. private string T_read;
  72. public string T_Read
  73. {
  74. get { return T_read; }
  75. set
  76. {
  77. SetProperty(ref T_read, value);
  78. }
  79. }
  80. private string T_full;
  81. public string T_Full
  82. {
  83. get { return T_full; }
  84. set
  85. {
  86. SetProperty(ref T_full, value);
  87. }
  88. }
  89. private string T_continuousScroll;
  90. public string T_ContinuousScroll
  91. {
  92. get { return T_continuousScroll; }
  93. set
  94. {
  95. SetProperty(ref T_continuousScroll, value);
  96. }
  97. }
  98. private string T_pageBreak;
  99. public string T_PageBreak
  100. {
  101. get { return T_pageBreak; }
  102. set
  103. {
  104. SetProperty(ref T_pageBreak, value);
  105. }
  106. }
  107. private string T_rotateTitle;
  108. public string T_RotateTitle
  109. {
  110. get { return T_rotateTitle; }
  111. set
  112. {
  113. SetProperty(ref T_rotateTitle, value);
  114. }
  115. }
  116. private void InitString()
  117. {
  118. T_Title = App.MainPageLoader.GetString("ViewProperties_Title");
  119. T_ModeTitle = App.MainPageLoader.GetString("ViewProperties_Mode");
  120. T_Single = App.MainPageLoader.GetString("ViewProperties_Single");
  121. T_Two = App.MainPageLoader.GetString("ViewProperties_Two");
  122. T_Book = App.MainPageLoader.GetString("ViewProperties_Book");
  123. T_Read = App.MainPageLoader.GetString("ViewProperties_Read");
  124. T_Full = App.MainPageLoader.GetString("ViewProperties_Full");
  125. T_ContinuousScroll = App.MainPageLoader.GetString("ViewProperties_ContinuousScroll");
  126. T_PageBreak = App.MainPageLoader.GetString("ViewProperties_PageBreak");
  127. T_RotateTitle = App.MainPageLoader.GetString("ViewProperties_RotateTitle");
  128. }
  129. #endregion
  130. private IRegionManager region;
  131. private IDialogService dialogs;
  132. //记录 单页 双页 书本模式
  133. private ViewMode viewmode = ViewMode.Single;
  134. public CPDFViewer PDFViewer { get; set; }
  135. public CPDFViewer SplitScreenPDFViewer { get; set; }
  136. public BottomToolContentViewModel BottomToolContentViewModel { get; set; }
  137. public ViewContentViewModel ViewContentViewModel { get; set; }
  138. public string SplitScreenViewRegionName { get; set; }
  139. public string ThemesContentName { get; set; }
  140. private Visibility splitScreenViewVisible = Visibility.Collapsed;
  141. public OpenFileInfo OpenFileInfo = null;
  142. /// <summary>
  143. /// 控制Content的显示 用于显示分屏的模块
  144. /// </summary>
  145. public Visibility SplitScreenViewVisible
  146. {
  147. get { return splitScreenViewVisible; }
  148. set
  149. {
  150. SetProperty(ref splitScreenViewVisible, value);
  151. }
  152. }
  153. private bool isContinue = true;
  154. public bool IsContinue
  155. {
  156. get { return isContinue; }
  157. set
  158. {
  159. SetProperty(ref isContinue, value);
  160. if (value)
  161. {
  162. SetModeView();
  163. }
  164. }
  165. }
  166. private bool isPagesBreak = true;
  167. public bool IsPagesBreak
  168. {
  169. get { return isPagesBreak; }
  170. set
  171. {
  172. SetProperty(ref isPagesBreak, value);
  173. }
  174. }
  175. private bool isSingleView;
  176. public bool IsSingleView
  177. {
  178. get { return isSingleView; }
  179. set
  180. {
  181. SetProperty(ref isSingleView, value);
  182. if (value)
  183. {
  184. SetModeView();
  185. }
  186. }
  187. }
  188. private bool isTwoPageView;
  189. public bool IsTwoPageView
  190. {
  191. get { return isTwoPageView; }
  192. set
  193. {
  194. SetProperty(ref isTwoPageView, value);
  195. if (value)
  196. {
  197. SetModeView();
  198. }
  199. }
  200. }
  201. private bool isBookModeView;
  202. public bool IsBookModeView
  203. {
  204. get { return isBookModeView; }
  205. set
  206. {
  207. SetProperty(ref isBookModeView, value);
  208. if (value)
  209. {
  210. SetModeView();
  211. }
  212. }
  213. }
  214. private bool rBtnFullScreenIsChecked = false;
  215. public bool IsFullScreen
  216. {
  217. get { return rBtnFullScreenIsChecked; }
  218. set
  219. {
  220. SetProperty(ref rBtnFullScreenIsChecked, value);
  221. }
  222. }
  223. public DelegateCommand<object> SplitScreenCommand { get; set; }
  224. public DelegateCommand<object> DisableCommand { get; set; }
  225. public DelegateCommand SetViewModeCommand { get; set; }
  226. public DelegateCommand<object> ContinueCommand { get; set; }
  227. public DelegateCommand<object> PagesBreakCommand { get; set; }
  228. public DelegateCommand<object> RotateCommand { get; set; }
  229. public DelegateCommand OpenFullCommand { get; set; }
  230. public ViewModularContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  231. {
  232. InitString();
  233. region = regionManager;
  234. dialogs = dialogService;
  235. //未显示时无法注册上Region名称,所以需要短暂显示
  236. //SplitScreenViewVisible = Visibility.Visible;
  237. //SplitScreenViewRegionName = RegionNames.SplitScreenViewRegionName;
  238. ThemesContentName = RegionNames.ThemesContentName;
  239. //SplitScreenViewVisible = Visibility.Collapsed;
  240. SplitScreenCommand = new DelegateCommand<object>(SplitScreenEvent);
  241. DisableCommand = new DelegateCommand<object>(DisableEvent);
  242. SetViewModeCommand = new DelegateCommand(SetModeView);
  243. ContinueCommand = new DelegateCommand<object>(ContinueEvent);
  244. PagesBreakCommand = new DelegateCommand<object>(PagesBreakEvent);
  245. RotateCommand = new DelegateCommand<object>(RotateEvent);
  246. OpenFullCommand = new DelegateCommand(OpenFullWindow);
  247. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  248. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  249. {
  250. NavigationParameters parameters = new NavigationParameters();
  251. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  252. parameters.Add(ParameterNames.ViewModularContentViewModel, this);
  253. region.RequestNavigate(RegionNames.ThemesContentName, "ThemesContent", parameters);
  254. }
  255. ));
  256. }
  257. /// <summary>
  258. /// 进入全屏模式
  259. /// </summary>
  260. private void OpenFullWindow()
  261. {
  262. DialogParameters parameters = new DialogParameters();
  263. //因为全屏模式可能需要设置特定的页面模式,所以只传文件路径,新建一个PDFview对象
  264. parameters.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
  265. parameters.Add(ParameterNames.PassWord, PDFViewer.Tag == null ? "" : PDFViewer.Tag.ToString());
  266. dialogs.ShowDialog(DialogNames.FullScreenDialog, parameters, e =>
  267. {
  268. if (e.Result == ButtonResult.Cancel)
  269. {
  270. //TODO:弹窗提示打开全屏模式失败
  271. AlertsMessage alertsMessage = new AlertsMessage();
  272. alertsMessage.ShowDialog("", "Error", "OK");
  273. return;
  274. }
  275. else if (e.Result == ButtonResult.OK)
  276. {
  277. IsFullScreen = false;
  278. IsSingleView = true;
  279. }
  280. });
  281. }
  282. /// <summary>
  283. /// 旋转
  284. /// </summary>
  285. /// <param name="obj"></param>
  286. private void RotateEvent(object obj)
  287. {
  288. bool right = Convert.ToBoolean(obj);
  289. PDFViewer.RotatePage(PageRotate.Rotate90, right, PDFViewer.CurrentIndex);
  290. if (SplitScreenPDFViewer != null)
  291. {
  292. SplitScreenPDFViewer.RotatePage(PageRotate.Rotate90, right, SplitScreenPDFViewer.CurrentIndex);
  293. }
  294. //后续需要添加,缩略图旋转改变
  295. PDFViewer.UndoManager.CanSave = true;
  296. }
  297. /// <summary>
  298. /// 分页符
  299. /// </summary>
  300. /// <param name="obj"></param>
  301. private void PagesBreakEvent(object obj)
  302. {
  303. if (IsPagesBreak)
  304. {
  305. PDFViewer.SetPageSpacing(8);
  306. IsPagesBreak = true;
  307. }
  308. else
  309. {
  310. PDFViewer.SetPageSpacing(0);
  311. IsPagesBreak = false;
  312. }
  313. SaveMode(IsPagesBreak);
  314. }
  315. /// <summary>
  316. /// 设置显示模式
  317. /// </summary>
  318. private void SetModeView()
  319. {
  320. if (PDFViewer != null)
  321. {
  322. SetUpModeView(PDFViewer);
  323. }
  324. //if (App.SplitScreenPDFViewer != null)
  325. //{
  326. // SetUpModeView(App.SplitScreenPDFViewer);
  327. // SaveMode(App.SplitScreenPDFViewer.ModeView);
  328. //}
  329. SaveMode(PDFViewer.ModeView);
  330. }
  331. private void SetUpModeView(CPDFViewer pDFViewer)
  332. {
  333. if (IsContinue)
  334. {
  335. if (IsSingleView)
  336. {
  337. pDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  338. //App.SplitScreenViewMode = ViewMode.SingleContinuous;
  339. }
  340. else if (IsTwoPageView)
  341. {
  342. pDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
  343. //App.SplitScreenViewMode = ViewMode.DoubleContinuous;
  344. }
  345. else
  346. {
  347. pDFViewer.ChangeViewMode(ViewMode.BookContinuous);
  348. //App.SplitScreenViewMode = ViewMode.BookContinuous;
  349. }
  350. }
  351. else
  352. {
  353. if (IsSingleView)
  354. {
  355. pDFViewer.ChangeViewMode(ViewMode.Single);
  356. //App.SplitScreenViewMode = ViewMode.Single;
  357. }
  358. else if (IsTwoPageView)
  359. {
  360. pDFViewer.ChangeViewMode(ViewMode.Double);
  361. //App.SplitScreenViewMode = ViewMode.Double;
  362. }
  363. else
  364. {
  365. pDFViewer.ChangeViewMode(ViewMode.Book);
  366. //App.SplitScreenViewMode = ViewMode.Book;
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 连续滚动
  372. /// </summary>
  373. /// <param name="obj"></param>
  374. private void ContinueEvent(object obj)
  375. {
  376. SetModeView();
  377. }
  378. /// <summary>
  379. /// 保存模式到本地
  380. /// </summary>
  381. /// <param name="modeView"></param>
  382. private void SaveMode(object modeView)
  383. {
  384. OpenFileInfo fileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  385. if (fileInfo != null)
  386. {
  387. if (modeView is SplitMode)
  388. {
  389. fileInfo.LastSplitMode = PDFViewer.Mode;
  390. }
  391. else if (modeView is ViewMode)
  392. {
  393. fileInfo.LastViewMode = PDFViewer.ModeView;
  394. }
  395. else if (modeView is bool)
  396. {
  397. fileInfo.LastPageSpace = (bool)modeView;
  398. }
  399. SettingHelper.SetFileInfo(fileInfo);
  400. }
  401. }
  402. /// <summary>
  403. /// 分屏视图-单屏
  404. /// </summary>
  405. /// <param name="obj"></param>
  406. private void DisableEvent(object obj)
  407. {
  408. ViewContentViewModel.EnterSplitMode(EventAggregators.SplitMode.Single);
  409. OpenFileInfo.LastSplitMode = ComPDFKitViewer.SplitMode.None;
  410. }
  411. /// <summary>
  412. /// 分屏视图-垂直
  413. /// </summary>
  414. /// <param name="obj"></param>
  415. private void SplitScreenEvent(object obj)
  416. {
  417. if (obj is System.Windows.Controls.RadioButton radioButton)
  418. {
  419. IsContinue = true;
  420. IsPagesBreak = true;
  421. switch (radioButton.Tag.ToString())
  422. {
  423. case "VerticalSplit":
  424. ViewContentViewModel.EnterSplitMode(EventAggregators.SplitMode.Vertical);
  425. OpenFileInfo.LastSplitMode = ComPDFKitViewer.SplitMode.Vertical;
  426. break;
  427. case "HorizontalSplit":
  428. ViewContentViewModel.EnterSplitMode(EventAggregators.SplitMode.Horizontal);
  429. OpenFileInfo.LastSplitMode = ComPDFKitViewer.SplitMode.Horizontal;
  430. break;
  431. }
  432. }
  433. }
  434. public bool IsNavigationTarget(NavigationContext navigationContext)
  435. {
  436. return true;
  437. }
  438. public void OnNavigatedFrom(NavigationContext navigationContext)
  439. {
  440. }
  441. public void OnNavigatedTo(NavigationContext navigationContext)
  442. {
  443. CPDFViewer pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  444. BottomToolContentViewModel btnTool = navigationContext.Parameters["BottomToolContentViewModel"] as BottomToolContentViewModel;
  445. if (pdfview != null && btnTool != null)
  446. {
  447. BottomToolContentViewModel = btnTool;
  448. PDFViewer = pdfview;
  449. ViewContentViewModel = BottomToolContentViewModel.ViewContentViewModel;
  450. OpenFileInfo = BottomToolContentViewModel.OpenFileInfo;
  451. }
  452. else
  453. {
  454. return;
  455. }
  456. IsSingleView = BottomToolContentViewModel.IsSingleView;
  457. IsTwoPageView = BottomToolContentViewModel.IsDoubleView;
  458. IsBookModeView = BottomToolContentViewModel.IsBookMode;
  459. IsContinue = BottomToolContentViewModel.IsContinue;
  460. PDFViewer.InfoChanged += PDFViewer_InfoChanged;
  461. }
  462. /// <summary>
  463. /// 和底部工具栏联动
  464. /// </summary>
  465. /// <param name="sender"></param>
  466. /// <param name="e"></param>
  467. private void PDFViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  468. {
  469. if (e.Key == "ViewMode")
  470. {
  471. GetModeView((ViewMode)e.Value);
  472. }
  473. }
  474. private void GetModeView(ViewMode mode)
  475. {
  476. if ((int)mode % 2 == 0)
  477. {
  478. if (!IsContinue)
  479. {
  480. IsContinue = true;
  481. }
  482. }
  483. else
  484. {
  485. if (IsContinue)
  486. {
  487. IsContinue = false;
  488. }
  489. }
  490. if ((int)mode <= 2)
  491. {
  492. if (!isSingleView)
  493. {
  494. IsSingleView = true;
  495. }
  496. }
  497. else if ((int)mode <= 4)
  498. {
  499. if (!isTwoPageView)
  500. {
  501. IsTwoPageView = true;
  502. }
  503. }
  504. else
  505. {
  506. if (!isBookModeView)
  507. {
  508. IsBookModeView = true;
  509. }
  510. }
  511. }
  512. }
  513. }