AnnotToolContentViewModel.Command.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument.Action;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using ComPDFKitViewer.PdfViewer;
  7. using PDF_Office.CustomControl;
  8. using PDF_Office.EventAggregators;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Properties;
  11. using PDF_Office.ViewModels.BOTA;
  12. using PDF_Office.Views.BOTA;
  13. using PDFSettings;
  14. using Prism.Mvvm;
  15. using Prism.Regions;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows;
  22. using System.Windows.Controls;
  23. using System.Windows.Controls.Primitives;
  24. using System.Windows.Media;
  25. using System.Diagnostics;
  26. namespace PDF_Office.ViewModels.Tools
  27. {
  28. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  29. {
  30. #region 事件绑定和解绑
  31. private void BindingEvent()
  32. {
  33. //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
  34. //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
  35. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  36. propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  37. propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
  38. propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
  39. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  40. propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  41. }
  42. private void UnBindingEvent()
  43. {
  44. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  45. propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
  46. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  47. }
  48. private void BindingPDFViewerHandler()
  49. {
  50. //来自PDFViewer的响应事件
  51. if (PDFViewer != null)
  52. {
  53. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  54. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  55. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  56. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  57. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  58. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  59. PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
  60. PDFViewer.WidgetClickHander += PDFViewer_WidgetClickHander;
  61. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  62. PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
  63. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  64. PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
  65. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  66. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  67. }
  68. }
  69. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  70. {
  71. if (action == null)
  72. {
  73. return;
  74. }
  75. switch (action.ActionType)
  76. {
  77. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  78. if (PDFViewer != null)
  79. {
  80. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  81. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  82. if (dest != null)
  83. {
  84. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  85. }
  86. }
  87. break;
  88. case C_ACTION_TYPE.ACTION_TYPE_URI:
  89. {
  90. CPDFUriAction uriAction = action as CPDFUriAction;
  91. string uri = uriAction.GetUri();
  92. try
  93. {
  94. if (!string.IsNullOrEmpty(uri))
  95. {
  96. Process.Start(uri);
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. }
  102. }
  103. break;
  104. }
  105. }
  106. private void UnBindingPDFViewerHandler()
  107. {
  108. if (PDFViewer != null)
  109. {
  110. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  111. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  112. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  113. PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
  114. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  115. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  116. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  117. }
  118. }
  119. #endregion 事件绑定和解绑
  120. #region PDFViewer事件
  121. //选中和非选中注释
  122. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  123. {
  124. if (e != null)
  125. {
  126. var annot = e.AnnotItemsList[0];
  127. if (annot != null)
  128. {
  129. if (e.AnnotItemsList.Count == 1)
  130. {
  131. //IsAnnotCreateReset:是否为创建注释的状态
  132. if (e.IsAnnotCreateReset == false)
  133. {
  134. GetSelectedAnnots(e);
  135. }
  136. else
  137. {
  138. switch (annot.EventType)
  139. {
  140. case AnnotArgsType.AnnotLink:
  141. //viewContentViewModel.IsCreateLink = false;
  142. GetLink(e.AnnotItemsList, e);
  143. PDFViewer.SetToolParam(annot);
  144. break;
  145. }
  146. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  147. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  148. annot.EventType != AnnotArgsType.AnnotUnderline &&
  149. annot.EventType != AnnotArgsType.AnnotHighlight &&
  150. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  151. annot.EventType != AnnotArgsType.AnnotLink &&
  152. annot.EventType != AnnotArgsType.AnnotFreehand &&
  153. annot.EventType != AnnotArgsType.AnnotSticky
  154. )
  155. {
  156. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  157. {
  158. foreach (var item in ToolExpandDict)
  159. {
  160. if (item.Value == e.AnnotItemsList[0].EventType)
  161. {
  162. annot = null;//新建注释时,回到默认值
  163. FindAnnotTypeKey(item.Key, ref annot);
  164. break;
  165. }
  166. }
  167. }
  168. }
  169. //else
  170. PDFViewer.SetToolParam(annot);
  171. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  172. if (isRightMenuAddAnnot)
  173. {
  174. ShowPropertyPanel(false);
  175. }
  176. else
  177. {
  178. ShowPropertyPanel();
  179. }
  180. }
  181. }
  182. else
  183. {
  184. bool isDifferentAnnotTyle = false;
  185. var lastAnnot = annot;
  186. foreach (var item in e.AnnotItemsList)
  187. {
  188. if (lastAnnot.EventType != item.EventType)
  189. {
  190. if ((isShapAnnot(annot) == true && isShapAnnot(item) == true) || (isHightAnnot(annot) == true && isHightAnnot(item) == true))
  191. {
  192. lastAnnot = item;
  193. continue;
  194. }
  195. lastAnnot = item;
  196. isDifferentAnnotTyle = true;
  197. break;
  198. }
  199. }
  200. if (isDifferentAnnotTyle)
  201. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  202. else
  203. GetSelectedAnnots(e);
  204. }
  205. }
  206. //注释列表同步选中
  207. var list = e.GetPageAnnotsIndex();
  208. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  209. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  210. {
  211. if (list.Keys.Count == 0)
  212. {
  213. return;
  214. }
  215. var pageindex = new List<int>(list.Keys);
  216. List<int> annotes = new List<int>();
  217. list.TryGetValue(pageindex[0], out annotes);
  218. int annoteindex = annotes[0];
  219. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  220. if (viewModel != null)
  221. {
  222. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  223. }
  224. }
  225. }
  226. else
  227. {
  228. if (BtnLinkIsChecked == false)
  229. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  230. }
  231. }
  232. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  233. {
  234. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  235. annot.EventType == AnnotArgsType.AnnotSquare ||
  236. annot.EventType == AnnotArgsType.AnnotLine
  237. )
  238. {
  239. return true;
  240. }
  241. else
  242. {
  243. return false;
  244. }
  245. }
  246. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  247. {
  248. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  249. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  250. annot.EventType == AnnotArgsType.AnnotHighlight ||
  251. annot.EventType == AnnotArgsType.AnnotStrikeout
  252. )
  253. {
  254. return true;
  255. }
  256. else
  257. {
  258. return false;
  259. }
  260. }
  261. private void GetSelectedAnnots(AnnotAttribEvent e)
  262. {
  263. var annot = e.AnnotItemsList[0];
  264. switch (annot.EventType)
  265. {
  266. case AnnotArgsType.AnnotHighlight:
  267. GetHighLight(e.AnnotItemsList);
  268. break;
  269. case AnnotArgsType.AnnotUnderline:
  270. GetUnderLine(e.AnnotItemsList);
  271. break;
  272. case AnnotArgsType.AnnotStrikeout:
  273. GetStrikeout(e.AnnotItemsList);
  274. break;
  275. case AnnotArgsType.AnnotSquiggly:
  276. GetSquiggly(e.AnnotItemsList);
  277. break;
  278. case AnnotArgsType.AnnotFreehand:
  279. GetFreehand(e.AnnotItemsList);
  280. break;
  281. case AnnotArgsType.AnnotFreeText:
  282. GetFreetext(e.AnnotItemsList);
  283. break;
  284. case AnnotArgsType.AnnotSquare:
  285. GetRect(e.AnnotItemsList);
  286. break;
  287. case AnnotArgsType.AnnotCircle:
  288. GetCircle(e.AnnotItemsList);
  289. break;
  290. case AnnotArgsType.AnnotLine:
  291. bool isLine = true;
  292. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  293. {
  294. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE)
  295. {
  296. isLine = false;
  297. }
  298. }
  299. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  300. {
  301. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE)
  302. {
  303. isLine = false;
  304. }
  305. }
  306. if (isLine)
  307. GetArrowLine("Line", e.AnnotItemsList);
  308. else
  309. GetArrowLine("Arrow", e.AnnotItemsList);
  310. break;
  311. case AnnotArgsType.AnnotLink:
  312. //viewContentViewModel.IsCreateLink = false;
  313. GetLink(e.AnnotItemsList, e);
  314. break;
  315. case AnnotArgsType.AnnotSticky:
  316. GetStickyNote(e.AnnotItemsList);
  317. break;
  318. }
  319. }
  320. //在注释工具的状态下,右键菜单
  321. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  322. {
  323. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  324. return;
  325. switch (e.CommandType)
  326. {
  327. case CommandType.Context:
  328. if (e.AnnotEventArgsList.Count > 0)
  329. {
  330. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  331. {
  332. //绑定标记密文处右键菜单
  333. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  334. }
  335. else
  336. {
  337. if (e.AnnotEventArgsList.Count == 1)
  338. {
  339. var selectedAnnot = e.AnnotEventArgsList[0];
  340. switch (selectedAnnot.EventType)
  341. {
  342. case AnnotArgsType.AnnotHighlight:
  343. case AnnotArgsType.AnnotUnderline:
  344. case AnnotArgsType.AnnotStrikeout:
  345. case AnnotArgsType.AnnotSquiggly:
  346. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  347. break;
  348. case AnnotArgsType.AnnotFreehand:
  349. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  350. break;
  351. case AnnotArgsType.AnnotFreeText:
  352. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  353. break;
  354. case AnnotArgsType.AnnotSticky:
  355. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  356. break;
  357. case AnnotArgsType.AnnotSquare:
  358. case AnnotArgsType.AnnotCircle:
  359. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  360. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  361. break;
  362. case AnnotArgsType.AnnotLine:
  363. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  364. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  365. break;
  366. case AnnotArgsType.AnnotLink:
  367. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  368. break;
  369. case AnnotArgsType.AnnotStamp:
  370. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  371. break;
  372. }
  373. }
  374. else
  375. {
  376. bool isHigh = true;//是否为高亮
  377. foreach (var item in e.AnnotEventArgsList)
  378. {
  379. if (isHightAnnot(item) == false)
  380. {
  381. isHigh = false;
  382. break;
  383. }
  384. }
  385. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  386. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  387. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  388. }
  389. }
  390. if (e.PopupMenu != null)
  391. {
  392. e.Handle = true;
  393. }
  394. }
  395. else
  396. {
  397. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  398. {
  399. e.PopupMenu = NoneSelectAnnotContextMenu(sender, e);
  400. if (e.PopupMenu != null)
  401. {
  402. e.Handle = true;
  403. }
  404. }
  405. else
  406. {
  407. e.PopupMenu = ViewerContextMenu(sender);
  408. if (e.PopupMenu != null)
  409. {
  410. e.Handle = true;
  411. }
  412. }
  413. }
  414. break;
  415. }
  416. }
  417. /// <summary>
  418. /// 内容选择工具
  419. /// </summary>
  420. /// <param name="sender"></param>
  421. /// <param name="e"></param>
  422. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  423. {
  424. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  425. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  426. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  427. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  428. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  429. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  430. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  431. {
  432. e.PopupMenu = popMenu;
  433. e.Handle = true;
  434. if (popMenu != null && popMenu.Items.Count == 5)
  435. {
  436. //复制
  437. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  438. menuItem.CommandTarget = PDFViewer;
  439. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  440. //导出
  441. menuItem = popMenu.Items[1] as MenuItem;
  442. menuItem.CommandTarget = PDFViewer;
  443. if (menuItem.Items.Count == 3)
  444. {
  445. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  446. menuItem1.CommandTarget = PDFViewer;
  447. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  448. menuItem1 = menuItem.Items[1] as MenuItem;
  449. menuItem1.CommandTarget = PDFViewer;
  450. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  451. menuItem1 = menuItem.Items[2] as MenuItem;
  452. menuItem1.CommandTarget = PDFViewer;
  453. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  454. }
  455. //裁剪
  456. menuItem = popMenu.Items[2] as MenuItem;
  457. menuItem.CommandTarget = PDFViewer;
  458. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  459. //缩放至所选区域
  460. menuItem = popMenu.Items[3] as MenuItem;
  461. menuItem.CommandTarget = PDFViewer;
  462. menuItem.Visibility = Visibility.Collapsed;
  463. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  464. //打印
  465. menuItem = popMenu.Items[4] as MenuItem;
  466. menuItem.CommandTarget = PDFViewer;
  467. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  468. }
  469. }
  470. }
  471. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  472. {
  473. switch (e.Key)
  474. {
  475. case "CloseSnap":
  476. {
  477. #region to do
  478. //var item = PDFViewerTab.SelectedItem as TabItem;
  479. //if (item == null)
  480. //{
  481. // ClearSelectedToolPanel();
  482. // return;
  483. //}
  484. //Grid grid = item.Content as Grid;
  485. //if (grid == null || grid.Children.Count == 0)
  486. //{
  487. // ClearSelectedToolPanel();
  488. // return;
  489. //}
  490. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  491. //if (pdfViewer == null)
  492. //{
  493. // ClearSelectedToolPanel();
  494. // return;
  495. //}
  496. #endregion to do
  497. switch (PDFViewer.MouseMode)
  498. {
  499. case MouseModes.SelectTextTool:
  500. break;
  501. default:
  502. BtnSelecttoolIsChecked = false;
  503. BtnHandIsChecked = true;
  504. PDFViewer.EnableZoom(true);
  505. PDFViewer.EnableScroll(true);
  506. break;
  507. }
  508. }
  509. break;
  510. default:
  511. break;
  512. }
  513. }
  514. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  515. {
  516. if (e != null && e.Count > 0)
  517. {
  518. for (int i = 0; i < e.Count; i++)
  519. {
  520. AnnotEditEvent editEvent = e[i];
  521. switch (editEvent.EditAction)
  522. {
  523. case ActionType.Add:
  524. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  525. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  526. {
  527. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  528. if (viewModel != null)
  529. {
  530. int pageindex = editEvent.PageIndex;
  531. int annotindex = editEvent.AnnotIndex;
  532. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  533. }
  534. }
  535. break;
  536. case ActionType.Del:
  537. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  538. if (isTabItemAnnotation)
  539. {
  540. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  541. if (viewModel != null)
  542. {
  543. int pageindex = editEvent.PageIndex;
  544. int annotindex = editEvent.AnnotIndex;
  545. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  546. }
  547. }
  548. break;
  549. case ActionType.Modify:
  550. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  551. if (bOTAContent.TabItemAnnotation.IsSelected)
  552. {
  553. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  554. if (viewModel != null)
  555. {
  556. int pageindex = editEvent.PageIndex;
  557. int annotindex = editEvent.AnnotIndex;
  558. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  559. }
  560. }
  561. break;
  562. case ActionType.TextEdit:
  563. break;
  564. default:
  565. break;
  566. }
  567. }
  568. }
  569. }
  570. private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
  571. {
  572. }
  573. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  574. {
  575. if (e != null && e.DrawContext != null)
  576. {
  577. Rect hoverRect = new Rect(
  578. e.PaintRect.Left - 2,
  579. e.PaintRect.Top - 2,
  580. e.PaintRect.Width + 4,
  581. e.PaintRect.Height + 4);
  582. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)),1);
  583. hoverPen.DashStyle = DashStyles.Dash;
  584. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  585. }
  586. }
  587. #endregion PDFViewer事件
  588. #region BindingEvent事件
  589. private void AnnotProperty_DefaultStored(object sender, object e)
  590. {
  591. }
  592. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  593. {
  594. if (e != null)
  595. {
  596. AnnotHandlerEventArgs annotArgs = null;
  597. foreach (AnnotArgsType argsType in e.Keys)
  598. {
  599. switch (argsType)
  600. {
  601. case AnnotArgsType.AnnotSquare:
  602. annotArgs = GetRect();
  603. break;
  604. case AnnotArgsType.AnnotCircle:
  605. annotArgs = GetCircle();
  606. break;
  607. case AnnotArgsType.AnnotLine:
  608. var LineTag = e[argsType] as string;
  609. annotArgs = GetArrowLine(LineTag);
  610. break;
  611. }
  612. if (annotArgs != null)
  613. {
  614. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  615. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  616. PDFViewer.SetToolParam(annotArgs);
  617. }
  618. ShowPropertyPanel();
  619. }
  620. }
  621. }
  622. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  623. {
  624. if (e != null)
  625. {
  626. foreach (AnnotArgsType argsType in e.Keys)
  627. {
  628. switch (argsType)
  629. {
  630. case AnnotArgsType.AnnotHighlight:
  631. if (e[argsType] is Color)
  632. {
  633. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  634. }
  635. if (e[argsType] is double)
  636. {
  637. HighLightOpacity = (double)e[argsType];
  638. }
  639. break;
  640. case AnnotArgsType.AnnotUnderline:
  641. if (e[argsType] is Color)
  642. {
  643. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  644. }
  645. if (e[argsType] is double)
  646. {
  647. underLineOpacity = (double)e[argsType];
  648. }
  649. break;
  650. case AnnotArgsType.AnnotSquiggly:
  651. if (e[argsType] is Color)
  652. {
  653. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  654. }
  655. if (e[argsType] is double)
  656. {
  657. SquigglyOpacity = (double)e[argsType];
  658. }
  659. break;
  660. case AnnotArgsType.AnnotStrikeout:
  661. if (e[argsType] is Color)
  662. {
  663. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  664. }
  665. if (e[argsType] is double)
  666. {
  667. StrikeoutOpacity = (double)e[argsType];
  668. }
  669. break;
  670. case AnnotArgsType.AnnotFreehand:
  671. if (e[argsType] is Color)
  672. {
  673. // FreehandPath.Fill = new SolidColorBrush((Color)e[argsType]);
  674. }
  675. if (e[argsType] is double)
  676. {
  677. // FreehandPath.Opacity = (double)e[argsType];
  678. }
  679. break;
  680. case AnnotArgsType.AnnotErase:
  681. if (e[argsType] is ToggleButton)
  682. {
  683. ToggleButton clickBtn = e[argsType] as ToggleButton;
  684. if (clickBtn.IsChecked == true)
  685. {
  686. if (clickBtn.Tag.ToString() == "PenBtn")
  687. {
  688. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  689. btn.Tag = "Freehand"; btn.IsChecked = true;
  690. BtnMyTools_Click(btn);
  691. break;
  692. }
  693. EraseArgs eraseArgs = new EraseArgs();
  694. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  695. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  696. eraseArgs.Thickness = 10;
  697. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  698. if (annotProperty != null)
  699. {
  700. eraseArgs.Thickness = annotProperty.Thickness;
  701. }
  702. PDFViewer.ClearSelectAnnots(false);
  703. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  704. PDFViewer.SetToolParam(eraseArgs);
  705. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  706. if (eraseArgs != null)
  707. eraseArgsList.Add(eraseArgs);
  708. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  709. }
  710. }
  711. break;
  712. }
  713. }
  714. }
  715. }
  716. #endregion BindingEvent事件
  717. }
  718. }