AnnotToolContentViewModel.Command.cs 39 KB

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