ScreenAnnotationDialogViewModel.cs 33 KB

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