AnnotToolContentViewModel.Command.cs 38 KB

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