ScreenAnnotationDialogViewModel.cs 31 KB

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