AnnotToolContentViewModel.Command.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. var strLineAnnotTag = "";
  159. if(e.AnnotItemsList[0] is LineAnnotArgs)
  160. {
  161. var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  162. if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  163. {
  164. strLineAnnotTag = "Line";
  165. }
  166. else
  167. {
  168. strLineAnnotTag = "Arrow";
  169. }
  170. }
  171. foreach (var item in ToolExpandDict)
  172. {
  173. if (item.Value == e.AnnotItemsList[0].EventType)
  174. {
  175. annot = null;//新建注释时,回到默认值
  176. if(string.IsNullOrEmpty(strLineAnnotTag))
  177. {
  178. FindAnnotTypeKey(item.Key, ref annot);
  179. break;
  180. }
  181. else
  182. {
  183. if(strLineAnnotTag == item.Key)
  184. {
  185. FindAnnotTypeKey(item.Key, ref annot);
  186. break;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. //else
  194. PDFViewer.SetToolParam(annot);
  195. #region TO DO
  196. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  197. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  198. //{
  199. // ShowPropertyPanel(false);
  200. //}
  201. //else
  202. //{
  203. // ShowPropertyPanel();
  204. //}
  205. #endregion TO DO
  206. }
  207. }
  208. else
  209. {
  210. bool isDifferentAnnotTyle = false;
  211. var lastAnnot = annot;
  212. foreach (var item in e.AnnotItemsList)
  213. {
  214. if (lastAnnot.EventType != item.EventType)
  215. {
  216. if ((isShapAnnot(annot) == true && isShapAnnot(item) == true) || (isHightAnnot(annot) == true && isHightAnnot(item) == true))
  217. {
  218. lastAnnot = item;
  219. continue;
  220. }
  221. lastAnnot = item;
  222. isDifferentAnnotTyle = true;
  223. break;
  224. }
  225. }
  226. if (isDifferentAnnotTyle)
  227. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  228. else
  229. GetSelectedAnnots(e);
  230. }
  231. }
  232. //注释列表同步选中
  233. var list = e.GetPageAnnotsIndex();
  234. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  235. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  236. {
  237. if (list.Keys.Count == 0)
  238. {
  239. return;
  240. }
  241. var pageindex = new List<int>(list.Keys);
  242. List<int> annotes = new List<int>();
  243. list.TryGetValue(pageindex[0], out annotes);
  244. int annoteindex = annotes[0];
  245. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  246. if (viewModel != null)
  247. {
  248. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  249. }
  250. }
  251. }
  252. else
  253. {
  254. if (BtnLinkIsChecked == false)
  255. {
  256. if (PDFViewer.MouseMode != MouseModes.AnnotCreate && PDFViewer.MouseMode != MouseModes.PanTool)
  257. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  258. }
  259. }
  260. }
  261. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  262. {
  263. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  264. annot.EventType == AnnotArgsType.AnnotSquare ||
  265. annot.EventType == AnnotArgsType.AnnotLine
  266. )
  267. {
  268. return true;
  269. }
  270. else
  271. {
  272. return false;
  273. }
  274. }
  275. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  276. {
  277. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  278. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  279. annot.EventType == AnnotArgsType.AnnotHighlight ||
  280. annot.EventType == AnnotArgsType.AnnotStrikeout
  281. )
  282. {
  283. return true;
  284. }
  285. else
  286. {
  287. return false;
  288. }
  289. }
  290. private void GetSelectedAnnots(AnnotAttribEvent e)
  291. {
  292. var annot = e.AnnotItemsList[0];
  293. switch (annot.EventType)
  294. {
  295. case AnnotArgsType.AnnotHighlight:
  296. GetHighLight(e.AnnotItemsList);
  297. break;
  298. case AnnotArgsType.AnnotUnderline:
  299. GetUnderLine(e.AnnotItemsList);
  300. break;
  301. case AnnotArgsType.AnnotStrikeout:
  302. GetStrikeout(e.AnnotItemsList);
  303. break;
  304. case AnnotArgsType.AnnotSquiggly:
  305. GetSquiggly(e.AnnotItemsList);
  306. break;
  307. case AnnotArgsType.AnnotFreehand:
  308. GetFreehand(e.AnnotItemsList);
  309. break;
  310. case AnnotArgsType.AnnotFreeText:
  311. GetFreetext(e.AnnotItemsList);
  312. break;
  313. case AnnotArgsType.AnnotSquare:
  314. GetRect(e.AnnotItemsList);
  315. break;
  316. case AnnotArgsType.AnnotCircle:
  317. GetCircle(e.AnnotItemsList);
  318. break;
  319. case AnnotArgsType.AnnotLine:
  320. bool isLine = true;
  321. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  322. {
  323. 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)
  324. {
  325. isLine = false;
  326. }
  327. }
  328. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  329. {
  330. 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)
  331. {
  332. isLine = false;
  333. }
  334. }
  335. if (isLine)
  336. GetArrowLine("Line", e.AnnotItemsList);
  337. else
  338. GetArrowLine("Arrow", e.AnnotItemsList);
  339. break;
  340. case AnnotArgsType.AnnotLink:
  341. //viewContentViewModel.IsCreateLink = false;
  342. GetLink(e.AnnotItemsList, e);
  343. break;
  344. case AnnotArgsType.AnnotSticky:
  345. GetStickyNote(e.AnnotItemsList);
  346. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  347. customStickyPopup.GetPDFViewer = PDFViewer;
  348. break;
  349. case AnnotArgsType.AnnotStamp:
  350. GetStamp();
  351. break;
  352. }
  353. }
  354. //在注释工具的状态下,右键菜单
  355. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  356. {
  357. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  358. return;
  359. switch (e.CommandType)
  360. {
  361. case CommandType.Context:
  362. if (e.AnnotEventArgsList.Count > 0)
  363. {
  364. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  365. {
  366. //绑定标记密文处右键菜单
  367. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  368. }
  369. else
  370. {
  371. if (e.AnnotEventArgsList.Count == 1)
  372. {
  373. var selectedAnnot = e.AnnotEventArgsList[0];
  374. switch (selectedAnnot.EventType)
  375. {
  376. case AnnotArgsType.AnnotHighlight:
  377. case AnnotArgsType.AnnotUnderline:
  378. case AnnotArgsType.AnnotStrikeout:
  379. case AnnotArgsType.AnnotSquiggly:
  380. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  381. break;
  382. case AnnotArgsType.AnnotFreehand:
  383. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  384. break;
  385. case AnnotArgsType.AnnotFreeText:
  386. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  387. break;
  388. case AnnotArgsType.AnnotSticky:
  389. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  390. break;
  391. case AnnotArgsType.AnnotSquare:
  392. case AnnotArgsType.AnnotCircle:
  393. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  394. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  395. break;
  396. case AnnotArgsType.AnnotLine:
  397. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  398. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  399. break;
  400. case AnnotArgsType.AnnotLink:
  401. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  402. break;
  403. case AnnotArgsType.AnnotStamp:
  404. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  405. break;
  406. }
  407. }
  408. else
  409. {
  410. bool isHigh = true;//是否为高亮
  411. foreach (var item in e.AnnotEventArgsList)
  412. {
  413. if (isHightAnnot(item) == false)
  414. {
  415. isHigh = false;
  416. break;
  417. }
  418. }
  419. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  420. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  421. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  422. }
  423. }
  424. if (e.PopupMenu != null)
  425. {
  426. e.Handle = true;
  427. }
  428. }
  429. else
  430. {
  431. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  432. {
  433. e.PopupMenu = NoneSelectAnnotContextMenu(sender, e);
  434. if (e.PopupMenu != null)
  435. {
  436. e.Handle = true;
  437. }
  438. }
  439. else
  440. {
  441. e.PopupMenu = ViewerContextMenu(sender);
  442. if (e.PopupMenu != null)
  443. {
  444. e.Handle = true;
  445. }
  446. }
  447. }
  448. break;
  449. }
  450. }
  451. /// <summary>
  452. /// 内容选择工具
  453. /// </summary>
  454. /// <param name="sender"></param>
  455. /// <param name="e"></param>
  456. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  457. {
  458. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  459. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  460. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  461. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  462. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  463. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  464. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  465. {
  466. e.PopupMenu = popMenu;
  467. e.Handle = true;
  468. if (popMenu != null && popMenu.Items.Count == 5)
  469. {
  470. //复制
  471. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  472. menuItem.CommandTarget = PDFViewer;
  473. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  474. //导出
  475. menuItem = popMenu.Items[1] as MenuItem;
  476. menuItem.CommandTarget = PDFViewer;
  477. if (menuItem.Items.Count == 3)
  478. {
  479. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  480. menuItem1.CommandTarget = PDFViewer;
  481. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  482. menuItem1 = menuItem.Items[1] as MenuItem;
  483. menuItem1.CommandTarget = PDFViewer;
  484. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  485. menuItem1 = menuItem.Items[2] as MenuItem;
  486. menuItem1.CommandTarget = PDFViewer;
  487. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  488. }
  489. //裁剪
  490. menuItem = popMenu.Items[2] as MenuItem;
  491. menuItem.CommandTarget = PDFViewer;
  492. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  493. //缩放至所选区域
  494. menuItem = popMenu.Items[3] as MenuItem;
  495. menuItem.CommandTarget = PDFViewer;
  496. menuItem.Visibility = Visibility.Collapsed;
  497. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  498. //打印
  499. menuItem = popMenu.Items[4] as MenuItem;
  500. menuItem.CommandTarget = PDFViewer;
  501. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  502. }
  503. }
  504. }
  505. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  506. {
  507. switch (e.Key)
  508. {
  509. case "CloseSnap":
  510. {
  511. #region to do
  512. //var item = PDFViewerTab.SelectedItem as TabItem;
  513. //if (item == null)
  514. //{
  515. // ClearSelectedToolPanel();
  516. // return;
  517. //}
  518. //Grid grid = item.Content as Grid;
  519. //if (grid == null || grid.Children.Count == 0)
  520. //{
  521. // ClearSelectedToolPanel();
  522. // return;
  523. //}
  524. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  525. //if (pdfViewer == null)
  526. //{
  527. // ClearSelectedToolPanel();
  528. // return;
  529. //}
  530. #endregion to do
  531. switch (PDFViewer.MouseMode)
  532. {
  533. case MouseModes.SelectTextTool:
  534. break;
  535. default:
  536. BtnSelecttoolIsChecked = false;
  537. BtnHandIsChecked = true;
  538. PDFViewer.EnableZoom(true);
  539. PDFViewer.EnableScroll(true);
  540. break;
  541. }
  542. }
  543. break;
  544. default:
  545. break;
  546. }
  547. }
  548. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  549. {
  550. if (e != null && e.Count > 0)
  551. {
  552. for (int i = 0; i < e.Count; i++)
  553. {
  554. AnnotEditEvent editEvent = e[i];
  555. switch (editEvent.EditAction)
  556. {
  557. case ActionType.Add:
  558. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  559. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  560. {
  561. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  562. if (viewModel != null)
  563. {
  564. int pageindex = editEvent.PageIndex;
  565. int annotindex = editEvent.AnnotIndex;
  566. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  567. }
  568. }
  569. var annot = e[0].EditAnnotArgs;
  570. if (
  571. annot.EventType == AnnotArgsType.AnnotSquare ||
  572. annot.EventType == AnnotArgsType.AnnotCircle ||
  573. annot.EventType == AnnotArgsType.AnnotLine ||
  574. annot.EventType == AnnotArgsType.AnnotStamp
  575. )
  576. {
  577. PDFViewer.ClearSelectAnnots();
  578. PDFViewer.SelectAnnotation(annot.PageIndex, annot.AnnotIndex);
  579. }
  580. break;
  581. case ActionType.Del:
  582. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  583. if (isTabItemAnnotation)
  584. {
  585. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  586. if (viewModel != null)
  587. {
  588. int pageindex = editEvent.PageIndex;
  589. int annotindex = editEvent.AnnotIndex;
  590. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  591. }
  592. }
  593. break;
  594. case ActionType.Modify:
  595. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  596. if (bOTAContent.TabItemAnnotation.IsSelected)
  597. {
  598. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  599. if (viewModel != null)
  600. {
  601. int pageindex = editEvent.PageIndex;
  602. int annotindex = editEvent.AnnotIndex;
  603. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  604. }
  605. }
  606. break;
  607. case ActionType.TextEdit:
  608. break;
  609. default:
  610. break;
  611. }
  612. }
  613. }
  614. }
  615. private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
  616. {
  617. }
  618. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  619. {
  620. if (e != null && e.DrawContext != null)
  621. {
  622. Rect hoverRect = new Rect(
  623. e.PaintRect.Left - 2,
  624. e.PaintRect.Top - 2,
  625. e.PaintRect.Width + 4,
  626. e.PaintRect.Height + 4);
  627. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  628. hoverPen.DashStyle = DashStyles.Dash;
  629. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  630. }
  631. }
  632. #endregion PDFViewer事件
  633. #region BindingEvent事件
  634. private void AnnotProperty_DefaultStored(object sender, object e)
  635. {
  636. }
  637. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  638. {
  639. if (e != null)
  640. {
  641. AnnotHandlerEventArgs annotArgs = null;
  642. foreach (AnnotArgsType argsType in e.Keys)
  643. {
  644. switch (argsType)
  645. {
  646. case AnnotArgsType.AnnotSquare:
  647. annotArgs = GetRect();
  648. break;
  649. case AnnotArgsType.AnnotCircle:
  650. annotArgs = GetCircle();
  651. break;
  652. case AnnotArgsType.AnnotLine:
  653. var LineTag = e[argsType] as string;
  654. annotArgs = GetArrowLine(LineTag);
  655. break;
  656. }
  657. if (annotArgs != null)
  658. {
  659. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  660. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  661. PDFViewer.SetToolParam(annotArgs);
  662. }
  663. ShowPropertyPanel();
  664. }
  665. }
  666. }
  667. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  668. {
  669. if (e != null)
  670. {
  671. foreach (AnnotArgsType argsType in e.Keys)
  672. {
  673. switch (argsType)
  674. {
  675. case AnnotArgsType.AnnotHighlight:
  676. if (e[argsType] is Color)
  677. {
  678. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  679. }
  680. if (e[argsType] is double)
  681. {
  682. HighLightOpacity = (double)e[argsType];
  683. }
  684. break;
  685. case AnnotArgsType.AnnotUnderline:
  686. if (e[argsType] is Color)
  687. {
  688. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  689. }
  690. if (e[argsType] is double)
  691. {
  692. underLineOpacity = (double)e[argsType];
  693. }
  694. break;
  695. case AnnotArgsType.AnnotSquiggly:
  696. if (e[argsType] is Color)
  697. {
  698. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  699. }
  700. if (e[argsType] is double)
  701. {
  702. SquigglyOpacity = (double)e[argsType];
  703. }
  704. break;
  705. case AnnotArgsType.AnnotStrikeout:
  706. if (e[argsType] is Color)
  707. {
  708. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  709. }
  710. if (e[argsType] is double)
  711. {
  712. StrikeoutOpacity = (double)e[argsType];
  713. }
  714. break;
  715. case AnnotArgsType.AnnotFreehand:
  716. if(e[argsType] is FreehandAnnotArgs)
  717. {
  718. var annot = e[argsType] as FreehandAnnotArgs;
  719. if (annot != null)
  720. {
  721. if (propertyPanel != null)
  722. {
  723. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  724. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  725. propertyPanel.AnnotEvent = AnnotEvent;
  726. var AnnotEvents = new List<AnnotAttribEvent>();
  727. AnnotEvents.Add(AnnotEvent);
  728. propertyPanel.AnnotEvents = AnnotEvents;
  729. propertyPanel.annot = annot;
  730. //手绘注释工具按钮的属性
  731. // FreehandPath.Opacity = annot.Transparency;
  732. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  733. }
  734. PDFViewer.SetToolParam(annot);
  735. }
  736. }
  737. break;
  738. case AnnotArgsType.AnnotErase:
  739. if (e[argsType] is ToggleButton)
  740. {
  741. ToggleButton clickBtn = e[argsType] as ToggleButton;
  742. if (clickBtn.IsChecked == true)
  743. {
  744. if (clickBtn.Tag.ToString() == "PenBtn")
  745. {
  746. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  747. btn.Tag = "Freehand"; btn.IsChecked = true;
  748. BtnMyTools_Click(btn);
  749. break;
  750. }
  751. EraseArgs eraseArgs = new EraseArgs();
  752. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  753. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  754. eraseArgs.Thickness = 10;
  755. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  756. if (annotProperty != null)
  757. {
  758. eraseArgs.Thickness = annotProperty.Thickness;
  759. }
  760. PDFViewer.ClearSelectAnnots(false);
  761. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  762. PDFViewer.SetToolParam(eraseArgs);
  763. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  764. if (eraseArgs != null)
  765. eraseArgsList.Add(eraseArgs);
  766. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  767. }
  768. }
  769. break;
  770. }
  771. }
  772. }
  773. }
  774. #endregion BindingEvent事件
  775. }
  776. }