ScreenAnnotationDialogViewModel.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using Dropbox.Api.Users;
  4. using DryIoc;
  5. using ImTools;
  6. using Microsoft.Office.Interop.Word;
  7. using PDF_Master.CustomControl;
  8. using PDF_Master.CustomControl.CompositeControl;
  9. using PDF_Master.EventAggregators;
  10. using PDF_Master.Helper;
  11. using PDF_Master.Model;
  12. using PDF_Master.Model.BOTA;
  13. using Prism.Commands;
  14. using Prism.Common;
  15. using Prism.Events;
  16. using Prism.Mvvm;
  17. using Prism.Services.Dialogs;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Collections.ObjectModel;
  21. using System.Drawing;
  22. using System.Linq;
  23. using System.Runtime.CompilerServices;
  24. using System.Text;
  25. using System.Threading.Tasks;
  26. using System.Windows;
  27. using System.Windows.Annotations;
  28. using System.Windows.Controls;
  29. using System.Windows.Documents;
  30. using System.Windows.Forms;
  31. using System.Windows.Media;
  32. using DialogResult = Prism.Services.Dialogs.DialogResult;
  33. using ListBox = System.Windows.Controls.ListBox;
  34. namespace PDF_Master.ViewModels.Dialog.BOTA
  35. {
  36. internal class ScreenAnnotationDialogViewModel : BindableBase, IDialogAware
  37. {
  38. #region 文案
  39. private string T_style;
  40. public string T_Style
  41. {
  42. get { return T_style; }
  43. set
  44. {
  45. SetProperty(ref T_style, value);
  46. }
  47. }
  48. private string T_color;
  49. public string T_Color
  50. {
  51. get { return T_color; }
  52. set
  53. {
  54. SetProperty(ref T_color, value);
  55. }
  56. }
  57. private string T_author;
  58. public string T_Author
  59. {
  60. get { return T_author; }
  61. set
  62. {
  63. SetProperty(ref T_author, value);
  64. }
  65. }
  66. private string T_clear;
  67. public string T_Clear
  68. {
  69. get { return T_clear; }
  70. set
  71. {
  72. SetProperty(ref T_clear, value);
  73. }
  74. }
  75. private string T_apply;
  76. public string T_Apply
  77. {
  78. get { return T_apply; }
  79. set
  80. {
  81. SetProperty(ref T_apply, value);
  82. }
  83. }
  84. private string T_cancel;
  85. public string T_Cancel
  86. {
  87. get { return T_cancel; }
  88. set
  89. {
  90. SetProperty(ref T_cancel, value);
  91. }
  92. }
  93. private void InitString()
  94. {
  95. T_Style = App.MainPageLoader.GetString("Annotation_DialogStyle");
  96. T_Color = App.MainPageLoader.GetString("Annotation_DialogColor");
  97. T_Author = App.MainPageLoader.GetString("Annotation_DialogAuthor");
  98. T_Clear = App.MainPageLoader.GetString("Annotation_DialogClear");
  99. T_Apply = App.MainPageLoader.GetString("Annotation_DialogYes");
  100. T_Cancel = App.MainPageLoader.GetString("Annotation_DialogNo");
  101. }
  102. #endregion 文案
  103. public string Title => "";
  104. public event Action<IDialogResult> RequestClose;
  105. #region 类型的显示隐藏
  106. /// <summary>
  107. /// 高亮字体
  108. /// </summary>
  109. private Visibility highlightVisibility = Visibility.Collapsed;
  110. public Visibility HighlightVisibility
  111. {
  112. get { return highlightVisibility; }
  113. set
  114. {
  115. SetProperty(ref highlightVisibility, value);
  116. }
  117. }
  118. /// <summary>
  119. /// 手绘
  120. /// </summary>
  121. private Visibility freeHandVisibility = Visibility.Collapsed;
  122. public Visibility FreeHandVisibility
  123. {
  124. get { return freeHandVisibility; }
  125. set
  126. {
  127. SetProperty(ref freeHandVisibility, value);
  128. }
  129. }
  130. /// <summary>
  131. /// 便签
  132. /// </summary>
  133. private Visibility annotStickyVisibility = Visibility.Collapsed;
  134. public Visibility AnnotStickyVisibility
  135. {
  136. get { return annotStickyVisibility; }
  137. set
  138. {
  139. SetProperty(ref annotStickyVisibility, value);
  140. }
  141. }
  142. /// <summary>
  143. /// 图章
  144. /// </summary>
  145. private Visibility annotStampVisibility = Visibility.Collapsed;
  146. public Visibility AnnotStampVisibility
  147. {
  148. get { return annotStampVisibility; }
  149. set
  150. {
  151. SetProperty(ref annotStampVisibility, value);
  152. }
  153. }
  154. /// <summary>
  155. /// 线
  156. /// </summary>
  157. private Visibility sharpLineVisibility = Visibility.Collapsed;
  158. public Visibility SharpLineVisibility
  159. {
  160. get { return sharpLineVisibility; }
  161. set
  162. {
  163. SetProperty(ref sharpLineVisibility, value);
  164. }
  165. }
  166. /// <summary>
  167. /// 箭头
  168. /// </summary>
  169. private Visibility sharpArrowVisibility = Visibility.Collapsed;
  170. public Visibility SharpArrowVisibility
  171. {
  172. get { return sharpArrowVisibility; }
  173. set
  174. {
  175. SetProperty(ref sharpArrowVisibility, value);
  176. }
  177. }
  178. /// <summary>
  179. /// 圆
  180. /// </summary>
  181. private Visibility annotCircleVisibility = Visibility.Collapsed;
  182. public Visibility AnnotCircleVisibility
  183. {
  184. get { return annotCircleVisibility; }
  185. set
  186. {
  187. SetProperty(ref annotCircleVisibility, value);
  188. }
  189. }
  190. /// <summary>
  191. /// 链接
  192. /// </summary>
  193. private Visibility annotLinkVisible = Visibility.Collapsed;
  194. public Visibility AnnotLinkVisible
  195. {
  196. get { return annotLinkVisible; }
  197. set
  198. {
  199. SetProperty(ref annotLinkVisible, value);
  200. }
  201. }
  202. /// <summary>
  203. /// 矩形
  204. /// </summary>
  205. private Visibility annotSquareVisibility = Visibility.Collapsed;
  206. public Visibility AnnotSquareVisibility
  207. {
  208. get { return annotSquareVisibility; }
  209. set
  210. {
  211. SetProperty(ref annotSquareVisibility, value);
  212. }
  213. }
  214. /// <summary>
  215. /// 文本注释
  216. /// </summary>
  217. private Visibility annotFreeTextVisibility = Visibility.Collapsed;
  218. public Visibility AnnotFreeTextVisibility
  219. {
  220. get { return annotFreeTextVisibility; }
  221. set
  222. {
  223. SetProperty(ref annotFreeTextVisibility, value);
  224. }
  225. }
  226. /// <summary>
  227. /// 删除线
  228. /// </summary>
  229. private Visibility annotStrikeoutVisibility = Visibility.Collapsed;
  230. public Visibility AnnotStrikeoutVisibility
  231. {
  232. get { return annotStrikeoutVisibility; }
  233. set
  234. {
  235. SetProperty(ref annotStrikeoutVisibility, value);
  236. }
  237. }
  238. /// <summary>
  239. /// 下划线
  240. /// </summary>
  241. private Visibility underLineVisibility = Visibility.Collapsed;
  242. public Visibility UnderLineVisibility
  243. {
  244. get { return underLineVisibility; }
  245. set
  246. {
  247. SetProperty(ref underLineVisibility, value);
  248. }
  249. }
  250. #endregion 类型的显示隐藏
  251. public DelegateCommand CancelCommand { get; set; }
  252. public DelegateCommand<object> OkCommnad { get; set; }
  253. public DelegateCommand<object> CleanCommand { get; set; }
  254. public DelegateCommand<object> LoadedCommand { get; set; }
  255. public ObservableCollection<AnnotationHandlerEventArgs> AnnotationListItems { get; set; }
  256. private ObservableCollection<ColorItem> annotationColors = new ObservableCollection<ColorItem>();
  257. public ObservableCollection<ColorItem> AnnotationColors
  258. {
  259. get { return annotationColors; }
  260. set
  261. {
  262. SetProperty(ref annotationColors, value);
  263. }
  264. }
  265. private ObservableCollection<AuthorItem> annotationAuthor = new ObservableCollection<AuthorItem>();
  266. public ObservableCollection<AuthorItem> AnnotationAuthor
  267. {
  268. get { return annotationAuthor; }
  269. set
  270. {
  271. SetProperty(ref annotationAuthor, value);
  272. }
  273. }
  274. private CustomIconToggleBtn btnHighlight = null;
  275. private CustomIconToggleBtn btnFreeHand = null;
  276. private CustomIconToggleBtn btnAnnotSticky = null;
  277. private CustomIconToggleBtn btnAnnotStamp = null;
  278. private CustomIconToggleBtn btnSharpLine = null;
  279. private CustomIconToggleBtn btnSharpArrow = null;
  280. private CustomIconToggleBtn btnAnnotCircle = null;
  281. private CustomIconToggleBtn btnAnnotSquare = null;
  282. private CustomIconToggleBtn btnAnnotFreeText = null;
  283. private CustomIconToggleBtn btnAnnotStrikeout = null;
  284. private CustomIconToggleBtn btnUnderLine = null;
  285. private CustomIconToggleBtn btnAnnotLink = null;
  286. private ListBox _ListColor = null;
  287. private ListBox _ListAuthor = null;
  288. private List<CustomIconToggleBtn> iconToggleBtns = new List<CustomIconToggleBtn>();
  289. private List<string> colors = new List<string>();
  290. private List<string> authors = new List<string>();
  291. private List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  292. public List<string> Colors { get => colors; set => colors = value; }
  293. public List<string> Authors { get => authors; set => authors = value; }
  294. public List<AnnotArgsType> AnnotArgsTypes { get => annotArgsTypes; set => annotArgsTypes = value; }
  295. public IEventAggregator events;
  296. public ScreenAnnotationDialogViewModel(IEventAggregator eventAggregator)
  297. {
  298. events = eventAggregator;
  299. //this.events.GetEvent<ScreenAnnotationEvent>().Subscribe(Loading, e => e.Unicode == App.mainWindowViewModel.SelectedItem.Unicode);
  300. LoadedCommand = new DelegateCommand<object>(Loaded);
  301. CancelCommand = new DelegateCommand(CancelEvent);
  302. OkCommnad = new DelegateCommand<object>(OkEvent);
  303. CleanCommand = new DelegateCommand<object>(CleanEvent);
  304. InitString();
  305. }
  306. private void Loaded(object obj)
  307. {
  308. if (obj is Object[] arrys1)
  309. {
  310. foreach (var item in arrys1)
  311. {
  312. if (item is CustomIconToggleBtn iconToggleBtn)
  313. {
  314. string tag = iconToggleBtn.Tag.ToString();
  315. switch (tag)
  316. {
  317. case "Highlight":
  318. btnHighlight = iconToggleBtn;
  319. iconToggleBtns.Add(iconToggleBtn);
  320. break;
  321. case "FreeHand":
  322. btnFreeHand = iconToggleBtn;
  323. iconToggleBtns.Add(iconToggleBtn);
  324. break;
  325. case "AnnotSticky":
  326. btnAnnotSticky = iconToggleBtn;
  327. iconToggleBtns.Add(iconToggleBtn);
  328. break;
  329. case "AnnotStamp":
  330. btnAnnotStamp = iconToggleBtn;
  331. iconToggleBtns.Add(iconToggleBtn);
  332. break;
  333. case "SharpLine":
  334. btnSharpLine = iconToggleBtn;
  335. iconToggleBtns.Add(iconToggleBtn);
  336. break;
  337. case "SharpArrow":
  338. btnSharpArrow = iconToggleBtn;
  339. iconToggleBtns.Add(iconToggleBtn);
  340. break;
  341. case "AnnotCircle":
  342. btnAnnotCircle = iconToggleBtn;
  343. iconToggleBtns.Add(iconToggleBtn);
  344. break;
  345. case "AnnotSquare":
  346. btnAnnotSquare = iconToggleBtn;
  347. iconToggleBtns.Add(iconToggleBtn);
  348. break;
  349. case "AnnotFreeText":
  350. btnAnnotFreeText = iconToggleBtn;
  351. iconToggleBtns.Add(iconToggleBtn);
  352. break;
  353. case "AnnotStrikeout":
  354. btnAnnotStrikeout = iconToggleBtn;
  355. iconToggleBtns.Add(iconToggleBtn);
  356. break;
  357. case "Underline":
  358. btnUnderLine = iconToggleBtn;
  359. iconToggleBtns.Add(iconToggleBtn);
  360. break;
  361. case "AnnotLink":
  362. btnAnnotLink = iconToggleBtn;
  363. iconToggleBtns.Add(iconToggleBtn);
  364. break;
  365. }
  366. }
  367. }
  368. SetBtnSelectedState(arrys1);
  369. }
  370. if (obj is CompositeCommandParameter composite)
  371. {
  372. if (composite.Parameter is Object[] arrys)
  373. {
  374. foreach (var item in arrys)
  375. {
  376. if (item is CustomIconToggleBtn iconToggleBtn)
  377. {
  378. string tag = iconToggleBtn.Tag.ToString();
  379. switch (tag)
  380. {
  381. case "Highlight":
  382. btnHighlight = iconToggleBtn;
  383. iconToggleBtns.Add(iconToggleBtn);
  384. break;
  385. case "FreeHand":
  386. btnFreeHand = iconToggleBtn;
  387. iconToggleBtns.Add(iconToggleBtn);
  388. break;
  389. case "AnnotSticky":
  390. btnAnnotSticky = iconToggleBtn;
  391. iconToggleBtns.Add(iconToggleBtn);
  392. break;
  393. case "AnnotStamp":
  394. btnAnnotStamp = iconToggleBtn;
  395. iconToggleBtns.Add(iconToggleBtn);
  396. break;
  397. case "SharpLine":
  398. btnSharpLine = iconToggleBtn;
  399. iconToggleBtns.Add(iconToggleBtn);
  400. break;
  401. case "SharpArrow":
  402. btnSharpArrow = iconToggleBtn;
  403. iconToggleBtns.Add(iconToggleBtn);
  404. break;
  405. case "AnnotCircle":
  406. btnAnnotCircle = iconToggleBtn;
  407. iconToggleBtns.Add(iconToggleBtn);
  408. break;
  409. case "AnnotSquare":
  410. btnAnnotSquare = iconToggleBtn;
  411. iconToggleBtns.Add(iconToggleBtn);
  412. break;
  413. case "AnnotFreeText":
  414. btnAnnotFreeText = iconToggleBtn;
  415. iconToggleBtns.Add(iconToggleBtn);
  416. break;
  417. case "AnnotStrikeout":
  418. btnAnnotStrikeout = iconToggleBtn;
  419. iconToggleBtns.Add(iconToggleBtn);
  420. break;
  421. case "Underline":
  422. btnUnderLine = iconToggleBtn;
  423. iconToggleBtns.Add(iconToggleBtn);
  424. break;
  425. case "AnnotLink":
  426. btnAnnotLink = iconToggleBtn;
  427. iconToggleBtns.Add(iconToggleBtn);
  428. break;
  429. }
  430. }
  431. }
  432. SetBtnSelectedState(arrys);
  433. }
  434. }
  435. }
  436. /// <summary>
  437. /// 记录设置按钮状态
  438. /// </summary>
  439. /// <param name="arrys"></param>
  440. private void SetBtnSelectedState(object[] arrys)
  441. {
  442. if (AnnotArgsTypes.Count > 0)
  443. {
  444. foreach (var item in AnnotArgsTypes)
  445. {
  446. switch (item)
  447. {
  448. case AnnotArgsType.AnnotNone:
  449. break;
  450. case AnnotArgsType.AnnotSquare:
  451. SetBtnType(btnAnnotSquare, false);
  452. break;
  453. case AnnotArgsType.AnnotCircle:
  454. SetBtnType(btnAnnotCircle, false);
  455. break;
  456. case AnnotArgsType.AnnotSticky:
  457. SetBtnType(btnAnnotSticky, false);
  458. break;
  459. case AnnotArgsType.AnnotLine:
  460. foreach (var annoitem in AnnotationListItems)
  461. {
  462. if (annoitem.AnnotHandlerEventArgs is LineAnnotArgs lineAnnotArgs)
  463. {
  464. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  465. {
  466. //箭头
  467. SetBtnType(btnSharpArrow, false);
  468. break;
  469. }
  470. else
  471. {
  472. //线
  473. SetBtnType(btnSharpLine, false);
  474. break;
  475. }
  476. }
  477. }
  478. break;
  479. case AnnotArgsType.AnnotFreehand:
  480. SetBtnType(btnFreeHand, false);
  481. break;
  482. case AnnotArgsType.AnnotErase:
  483. break;
  484. case AnnotArgsType.AnnotFreeText:
  485. SetBtnType(btnAnnotFreeText, false);
  486. break;
  487. case AnnotArgsType.AnnotStamp:
  488. SetBtnType(btnAnnotStamp, false);
  489. break;
  490. case AnnotArgsType.AnnotHighlight:
  491. SetBtnType(btnHighlight, false);
  492. break;
  493. case AnnotArgsType.AnnotUnderline:
  494. SetBtnType(btnUnderLine, false);
  495. break;
  496. case AnnotArgsType.AnnotStrikeout:
  497. SetBtnType(btnAnnotStrikeout, false);
  498. break;
  499. case AnnotArgsType.AnnotSquiggly:
  500. SetBtnType(btnAnnotSquare, false);
  501. break;
  502. case AnnotArgsType.AnnotLink:
  503. SetBtnType(btnAnnotLink, false);
  504. break;
  505. case AnnotArgsType.AnnotSelectTool:
  506. break;
  507. case AnnotArgsType.SnapshotTool:
  508. break;
  509. case AnnotArgsType.SnapshotWithEditTool:
  510. break;
  511. case AnnotArgsType.WidgetViewForm:
  512. break;
  513. case AnnotArgsType.AnnotSound:
  514. break;
  515. case AnnotArgsType.AnnotMedia:
  516. break;
  517. case AnnotArgsType.AnnotRedaction:
  518. break;
  519. default:
  520. break;
  521. }
  522. }
  523. }
  524. if (arrys[12] is System.Windows.Controls.ListBox listColor)
  525. {
  526. this._ListColor = listColor;
  527. if (Colors.Count > 0)
  528. {
  529. listColor.ItemsSource = AnnotationColors;
  530. foreach (var item in AnnotationColors)
  531. {
  532. foreach (var color in Colors)
  533. {
  534. if (item.Color.ToString() == color)
  535. {
  536. ListBoxItem myListBoxItem = (ListBoxItem)(listColor.ItemContainerGenerator.ContainerFromItem(item));
  537. myListBoxItem.IsSelected = true;
  538. }
  539. }
  540. }
  541. }
  542. }
  543. if (arrys[13] is System.Windows.Controls.ListBox listAuthor)
  544. {
  545. this._ListAuthor = listAuthor;
  546. if (Authors.Count > 0)
  547. {
  548. listAuthor.ItemsSource = AnnotationAuthor;
  549. foreach (var item in AnnotationAuthor)
  550. {
  551. foreach (var author in Authors)
  552. {
  553. if (item.Name == author)
  554. {
  555. ListBoxItem myListBoxItem = (ListBoxItem)(listAuthor.ItemContainerGenerator.ContainerFromItem(item));
  556. myListBoxItem.IsSelected = true;
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }
  563. /// <summary>
  564. /// 清除筛选项
  565. /// </summary>
  566. /// <param name="obj"></param>
  567. private void CleanEvent(Object obj)
  568. {
  569. for (int i = 0; i < iconToggleBtns.Count; i++)
  570. {
  571. SetBtnType(iconToggleBtns[i], true);
  572. }
  573. if (this._ListColor != null)
  574. {
  575. this._ListColor.SelectedItems.Clear();
  576. }
  577. if (this._ListAuthor != null)
  578. {
  579. this._ListAuthor.SelectedItems.Clear();
  580. }
  581. //DialogParameters valuePairs = new DialogParameters();
  582. //valuePairs.Add(ParameterNames.AnnotationCleanState, true);
  583. //RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  584. }
  585. /// <summary>
  586. /// 设置类型按钮状态
  587. /// </summary>
  588. /// <param name="btn"></param>
  589. private void SetBtnType(CustomIconToggleBtn btn, bool flag)
  590. {
  591. if (btn != null)
  592. {
  593. if (btn.IsChecked == flag)
  594. {
  595. btn.IsChecked = !flag;
  596. }
  597. }
  598. }
  599. /// <summary>
  600. /// 确认
  601. /// </summary>
  602. /// <param name="obj"></param>
  603. private void OkEvent(Object obj)
  604. {
  605. List<AnnotArgsType> styleDic = GetAnnotArgsType();
  606. List<string> colors = new List<string>();
  607. List<string> authors = new List<string>();
  608. if (this._ListColor != null)
  609. {
  610. if (this._ListColor.SelectedItems.Count > 0)
  611. {
  612. foreach (var item in this._ListColor.SelectedItems)
  613. {
  614. ColorItem color = item as ColorItem;
  615. colors.Add(color.Color.ToString());
  616. }
  617. }
  618. }
  619. if (this._ListAuthor != null)
  620. {
  621. if (this._ListAuthor.SelectedItems.Count > 0)
  622. {
  623. foreach (var item in this._ListAuthor.SelectedItems)
  624. {
  625. AuthorItem author = item as AuthorItem;
  626. authors.Add(author.Name);
  627. }
  628. }
  629. }
  630. DialogParameters valuePairs = new DialogParameters();
  631. valuePairs.Add(ParameterNames.AnnotArgsTypes, styleDic);
  632. valuePairs.Add(ParameterNames.AnnotationColors, colors);
  633. valuePairs.Add(ParameterNames.AnnotationAuthor, authors);
  634. valuePairs.Add(ParameterNames.AnnotationCleanState, false);
  635. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  636. }
  637. /// <summary>
  638. /// 获取类型按钮状态
  639. /// </summary>
  640. /// <param name="arrys"></param>
  641. /// <returns></returns>
  642. private List<AnnotArgsType> GetAnnotArgsType()
  643. {
  644. List<AnnotArgsType> styleDic = new List<AnnotArgsType>();
  645. //CustomIconToggleBtn btnHighlight = arrys[0] as CustomIconToggleBtn;
  646. //CustomIconToggleBtn btnFreeHand = arrys[1] as CustomIconToggleBtn;
  647. //CustomIconToggleBtn btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
  648. //CustomIconToggleBtn btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
  649. //CustomIconToggleBtn btnSharpLine = arrys[4] as CustomIconToggleBtn;
  650. //CustomIconToggleBtn btnSharpArrow = arrys[5] as CustomIconToggleBtn;
  651. //CustomIconToggleBtn btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
  652. //CustomIconToggleBtn btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
  653. //CustomIconToggleBtn btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
  654. //CustomIconToggleBtn btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
  655. //CustomIconToggleBtn btnUnderLine = arrys[10] as CustomIconToggleBtn;
  656. GetBtnAnnotArgsTypeState(btnHighlight, styleDic, AnnotArgsType.AnnotHighlight);
  657. GetBtnAnnotArgsTypeState(btnFreeHand, styleDic, AnnotArgsType.AnnotFreehand);
  658. GetBtnAnnotArgsTypeState(btnAnnotSticky, styleDic, AnnotArgsType.AnnotSticky);
  659. GetBtnAnnotArgsTypeState(btnAnnotStamp, styleDic, AnnotArgsType.AnnotStamp);
  660. GetBtnAnnotArgsTypeState(btnSharpLine, styleDic, AnnotArgsType.AnnotLine);
  661. GetBtnAnnotArgsTypeState(btnSharpArrow, styleDic, AnnotArgsType.AnnotLine);
  662. GetBtnAnnotArgsTypeState(btnAnnotCircle, styleDic, AnnotArgsType.AnnotCircle);
  663. GetBtnAnnotArgsTypeState(btnAnnotSquare, styleDic, AnnotArgsType.AnnotSquare);
  664. GetBtnAnnotArgsTypeState(btnAnnotFreeText, styleDic, AnnotArgsType.AnnotFreeText);
  665. GetBtnAnnotArgsTypeState(btnAnnotStrikeout, styleDic, AnnotArgsType.AnnotStrikeout);
  666. GetBtnAnnotArgsTypeState(btnUnderLine, styleDic, AnnotArgsType.AnnotUnderline);
  667. GetBtnAnnotArgsTypeState(btnAnnotLink, styleDic, AnnotArgsType.AnnotLink);
  668. return styleDic;
  669. }
  670. /// <summary>
  671. /// 添加被选中的类型按钮到集合
  672. /// </summary>
  673. /// <param name="btnType"></param>
  674. /// <param name="styleDic"></param>
  675. /// <param name="annotArgsType"></param>
  676. private void GetBtnAnnotArgsTypeState(CustomIconToggleBtn btnType, List<AnnotArgsType> styleDic, AnnotArgsType annotArgsType)
  677. {
  678. if (btnType != null)
  679. {
  680. if (btnType.IsChecked == true)
  681. {
  682. if (styleDic.IndexOf(annotArgsType) == -1)
  683. {
  684. styleDic.Add(annotArgsType);
  685. }
  686. }
  687. }
  688. }
  689. private void CancelEvent()
  690. {
  691. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  692. }
  693. public bool CanCloseDialog()
  694. {
  695. return true;
  696. }
  697. public void OnDialogClosed()
  698. {
  699. }
  700. /// <summary>
  701. /// 添加筛选颜色
  702. /// </summary>
  703. /// <param name="color"></param>
  704. private void GetAnnotationColors(System.Windows.Media.Color color)
  705. {
  706. if (AnnotationColors.Count > 0)
  707. {
  708. for (int i = 0; i < AnnotationColors.Count; i++)
  709. {
  710. System.Windows.Media.Color color1 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(AnnotationColors[i].Color.ToString());
  711. if (color1.R == color.R && color1.G == color.G && color1.B == color.B
  712. && color1.A == color.A)
  713. {
  714. AnnotationColors.Remove(AnnotationColors[i]);
  715. }
  716. }
  717. }
  718. AnnotationColors.Add(new ColorItem(color));
  719. }
  720. public void OnDialogOpened(IDialogParameters parameters)
  721. {
  722. ObservableCollection<AnnotationHandlerEventArgs> list;
  723. parameters.TryGetValue<ObservableCollection<AnnotationHandlerEventArgs>>(ParameterNames.AnnotationList, out list);
  724. AnnotationListItems = list;
  725. List<string> colors = new List<string>();
  726. List<string> authors = new List<string>();
  727. List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  728. parameters.TryGetValue<List<string>>(ParameterNames.AnnotationColors, out colors);
  729. parameters.TryGetValue<List<string>>(ParameterNames.AnnotationAuthor, out authors);
  730. parameters.TryGetValue<List<AnnotArgsType>>(ParameterNames.AnnotArgsTypes, out annotArgsTypes);
  731. if (colors != null)
  732. {
  733. this.Colors = colors;
  734. }
  735. if (authors != null)
  736. {
  737. this.Authors = authors;
  738. }
  739. if (annotArgsTypes != null)
  740. {
  741. this.AnnotArgsTypes = annotArgsTypes;
  742. }
  743. if (AnnotationListItems.Count <= 0)
  744. {
  745. return;
  746. }
  747. foreach (var item in AnnotationListItems)
  748. {
  749. AnnotationAuthor.Add(new AuthorItem(item.Author));
  750. AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
  751. switch (item.EventType)
  752. {
  753. case AnnotArgsType.AnnotFreeText://文本
  754. if (data is FreeTextAnnotArgs textAnnotArgs)
  755. {
  756. GetAnnotationColors(textAnnotArgs.FontColor);
  757. }
  758. AnnotFreeTextVisibility = Visibility.Visible;
  759. break;
  760. case AnnotArgsType.AnnotHighlight://高亮
  761. if (data is TextHighlightAnnotArgs highlightAnnotArgs)
  762. {
  763. GetAnnotationColors(highlightAnnotArgs.Color);
  764. }
  765. HighlightVisibility = Visibility.Visible;
  766. break;
  767. case AnnotArgsType.AnnotFreehand://手绘
  768. if (data is FreehandAnnotArgs freehandAnnotArgs)
  769. {
  770. GetAnnotationColors(freehandAnnotArgs.InkColor);
  771. }
  772. FreeHandVisibility = Visibility.Visible;
  773. break;
  774. case AnnotArgsType.AnnotSquiggly://波浪线
  775. break;
  776. case AnnotArgsType.AnnotStamp://图章
  777. AnnotStampVisibility = Visibility.Visible;
  778. break;
  779. case AnnotArgsType.AnnotStrikeout://删除线
  780. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  781. {
  782. GetAnnotationColors(textStrikeoutAnnotArgs.Color);
  783. }
  784. AnnotStrikeoutVisibility = Visibility.Visible;
  785. break;
  786. case AnnotArgsType.AnnotSticky://便签
  787. if (data is StickyAnnotArgs stickyAnnotArgs)
  788. {
  789. GetAnnotationColors(stickyAnnotArgs.Color);
  790. }
  791. AnnotStickyVisibility = Visibility.Visible;
  792. break;
  793. case AnnotArgsType.AnnotUnderline://下划线
  794. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  795. {
  796. GetAnnotationColors(textUnderlineAnnotArgs.Color);
  797. }
  798. UnderLineVisibility = Visibility.Visible;
  799. break;
  800. case AnnotArgsType.AnnotLine:
  801. if (data is LineAnnotArgs lineAnnotArgs)
  802. {
  803. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  804. {
  805. //箭头
  806. SharpArrowVisibility = Visibility.Visible;
  807. }
  808. else
  809. {
  810. //线
  811. SharpLineVisibility = Visibility.Visible;
  812. }
  813. GetAnnotationColors(lineAnnotArgs.LineColor);
  814. }
  815. break;
  816. case AnnotArgsType.AnnotSquare://矩形
  817. if (data is SquareAnnotArgs squareAnnotArgs)
  818. {
  819. GetAnnotationColors(squareAnnotArgs.BgColor);
  820. GetAnnotationColors(squareAnnotArgs.LineColor);
  821. }
  822. AnnotSquareVisibility = Visibility.Visible;
  823. break;
  824. case AnnotArgsType.AnnotCircle://圆
  825. if (data is CircleAnnotArgs circleAnnotArgs)
  826. {
  827. GetAnnotationColors(circleAnnotArgs.BgColor);
  828. GetAnnotationColors(circleAnnotArgs.LineColor);
  829. }
  830. AnnotCircleVisibility = Visibility.Visible;
  831. break;
  832. case AnnotArgsType.AnnotLink:
  833. AnnotLinkVisible = Visibility.Visible;
  834. break;
  835. }
  836. }
  837. AnnotationAuthor = new ObservableCollection<AuthorItem>(AnnotationAuthor.DistinctHelper(s => s.Name));
  838. AnnotationAuthor = new ObservableCollection<AuthorItem>(AnnotationAuthor.Where(a => string.IsNullOrEmpty(a.Name) != true));
  839. }
  840. }
  841. }