AnnotToolContentViewModel.Command.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.PDFDocument.Action;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.AnnotEvent;
  7. using ComPDFKitViewer.PdfViewer;
  8. using PDF_Master.CustomControl;
  9. using PDF_Master.EventAggregators;
  10. using PDF_Master.Helper;
  11. using PDF_Master.Model.AnnotPanel;
  12. using PDF_Master.Properties;
  13. using PDF_Master.ViewModels.BOTA;
  14. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  15. using PDF_Master.ViewModels.Tools.AnnotManager;
  16. using PDF_Master.Views.BOTA;
  17. using PDFSettings;
  18. using Prism.Mvvm;
  19. using Prism.Regions;
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Diagnostics;
  23. using System.Linq;
  24. using System.Windows;
  25. using System.Windows.Controls;
  26. using System.Windows.Controls.Primitives;
  27. using System.Windows.Input;
  28. using System.Windows.Media;
  29. namespace PDF_Master.ViewModels.Tools
  30. {
  31. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  32. {
  33. #region 事件绑定和解绑
  34. private void BindingEvent()
  35. {
  36. //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
  37. //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
  38. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  39. propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  40. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  41. propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  42. //快捷键
  43. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  44. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  45. }
  46. private void UnBindingEvent()
  47. {
  48. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  49. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  50. //快捷盘解绑
  51. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  52. }
  53. private void BindingPDFViewerHandler()
  54. {
  55. //来自PDFViewer的响应事件
  56. if (PDFViewer != null)
  57. {
  58. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  59. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  60. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  61. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  62. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  63. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  64. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  65. PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
  66. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  67. PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
  68. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  69. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  70. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  71. PDFViewer.PreviewMouseLeftButtonDown += PDFViewer_PreviewMouseLeftButtonDown;
  72. }
  73. }
  74. private void UnBindingPDFViewerHandler()
  75. {
  76. if (PDFViewer != null)
  77. {
  78. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  79. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  80. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  81. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  82. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  83. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  84. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  85. }
  86. }
  87. #endregion 事件绑定和解绑
  88. #region 与触发事件调用相关的函数
  89. //鼠标左键双击注释
  90. private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  91. {
  92. if (e.ClickCount == 1)
  93. {
  94. //if (sender is CPDFViewer pDFViewer)
  95. //{
  96. // if (pDFViewer.ToolManager.CurrentAnnotArgs != null)
  97. // {
  98. // if (pDFViewer.ToolManager.CurrentAnnotArgs is FreehandAnnotArgs freehand)
  99. // {
  100. // PDFViewer.SelectAnnotation(freehand.PageIndex, freehand.AnnotIndex);
  101. // }
  102. // }
  103. //}
  104. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemBookMark");
  105. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemBookMark.IsSelected == true)
  106. {
  107. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  108. }
  109. }
  110. if (e.ClickCount == 2)
  111. {
  112. if (CurrentSelectedAnnot != null)
  113. {
  114. var type = CurrentSelectedAnnot.EventType;
  115. if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText &&
  116. type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline && type != AnnotArgsType.AnnotStrikeout)
  117. {
  118. int dpi = DpiHelpers.Dpi;
  119. var rect = CurrentSelectedAnnot.ClientRect;
  120. rect = new Rect(
  121. rect.Left * PDFViewer.ZoomFactor,
  122. rect.Top * PDFViewer.ZoomFactor,
  123. rect.Width * PDFViewer.ZoomFactor,
  124. rect.Height * PDFViewer.ZoomFactor);
  125. var ui = PDFViewer.Parent as ContentControl;
  126. if (ui != null)
  127. {
  128. var point = e.GetPosition(ui);
  129. int pageIndex = 0;
  130. Point pagePoint = new Point(0, 0);
  131. //Todo:等黎总需要更新ComPDFKit.dll
  132. PDFViewer.ConvertViewPointToPage(point, out pageIndex, out pagePoint);
  133. if (pagePoint.X >= rect.Left && pagePoint.X <= rect.Right && pagePoint.Y >= rect.Top && pagePoint.Y <= rect.Bottom)
  134. PopAnnotNoteText(CurrentSelectedAnnot);
  135. }
  136. }
  137. if (type == AnnotArgsType.AnnotSticky)
  138. {
  139. (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
  140. }
  141. }
  142. }
  143. }
  144. //超链接跳转
  145. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  146. {
  147. if (action == null)
  148. {
  149. return;
  150. }
  151. switch (action.ActionType)
  152. {
  153. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  154. if (PDFViewer != null)
  155. {
  156. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  157. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  158. if (dest != null)
  159. {
  160. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  161. }
  162. }
  163. break;
  164. case C_ACTION_TYPE.ACTION_TYPE_URI:
  165. {
  166. CPDFUriAction uriAction = action as CPDFUriAction;
  167. string uri = uriAction.GetUri();
  168. try
  169. {
  170. if (!string.IsNullOrEmpty(uri))
  171. {
  172. Process.Start(uri);
  173. }
  174. }
  175. catch (Exception ex)
  176. {
  177. }
  178. }
  179. break;
  180. }
  181. }
  182. private void GetSelectedAnnots(AnnotAttribEvent e)
  183. {
  184. var annot = e.AnnotItemsList[0];
  185. switch (annot.EventType)
  186. {
  187. case AnnotArgsType.AnnotHighlight:
  188. GetHighLight(e.AnnotItemsList);
  189. break;
  190. case AnnotArgsType.AnnotUnderline:
  191. GetUnderLine(e.AnnotItemsList);
  192. break;
  193. case AnnotArgsType.AnnotStrikeout:
  194. GetStrikeout(e.AnnotItemsList);
  195. break;
  196. case AnnotArgsType.AnnotSquiggly:
  197. GetSquiggly(e.AnnotItemsList);
  198. break;
  199. case AnnotArgsType.AnnotFreehand:
  200. GetFreehand(e.AnnotItemsList);
  201. break;
  202. case AnnotArgsType.AnnotFreeText:
  203. GetFreetext(e.AnnotItemsList);
  204. break;
  205. case AnnotArgsType.AnnotSquare:
  206. GetRect(e.AnnotItemsList);
  207. break;
  208. case AnnotArgsType.AnnotCircle:
  209. GetCircle(e.AnnotItemsList);
  210. break;
  211. case AnnotArgsType.AnnotLine:
  212. bool isLine = true;
  213. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  214. {
  215. 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)
  216. {
  217. isLine = false;
  218. }
  219. }
  220. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  221. {
  222. 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)
  223. {
  224. isLine = false;
  225. }
  226. }
  227. if (isLine)
  228. GetArrowLine("Line", e.AnnotItemsList);
  229. else
  230. GetArrowLine("Arrow", e.AnnotItemsList);
  231. break;
  232. case AnnotArgsType.AnnotLink:
  233. //viewContentViewModel.IsCreateLink = false;
  234. //e.IsAnnotCreateReset= true;
  235. if (StrAnnotToolChecked == "Link")
  236. {
  237. propertyPanel.IsAddLink = false;
  238. }
  239. GetLink(e.AnnotItemsList, e);
  240. break;
  241. case AnnotArgsType.AnnotSticky:
  242. GetStickyNote(e.AnnotItemsList);
  243. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  244. customStickyPopup.GetPDFViewer = PDFViewer;
  245. if (e.IsAnnotCreateReset)
  246. {
  247. propertyPanel.annot = e.AnnotItemsList[0];
  248. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  249. propertyPanel.AnnotEvents = null;
  250. propertyPanel.AnnotEvent = AnnotEvent;
  251. propertyPanel.annotlists = e.AnnotItemsList;
  252. }
  253. break;
  254. case AnnotArgsType.AnnotStamp:
  255. if (e.IsAnnotCreateReset == false)
  256. {
  257. GetStamp();
  258. }
  259. break;
  260. }
  261. }
  262. /// <summary>
  263. /// 选中注释 区分签名、图章、手绘
  264. /// </summary>
  265. /// <param name="annotlist"></param>
  266. private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
  267. {
  268. if (annotlist == null || annotlist.Count == 0)
  269. return;
  270. var annot = annotlist[0];
  271. if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
  272. return;
  273. if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
  274. return;
  275. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  276. if (signAnnot == null)
  277. {
  278. //var key = ToolExpandDict.FirstOrDefault(q => q.Value == annot.EventType);
  279. //if (!string.IsNullOrEmpty(StrAnnotToolChecked))
  280. // StrAnnotToolChecked = key.Key.ToString();
  281. //if (annot.EventType == AnnotArgsType.AnnotStamp)
  282. //{
  283. // StrAnnotToolChecked = "Stamp";
  284. //}
  285. //else
  286. //{
  287. // StrAnnotToolChecked = "";
  288. //}
  289. }
  290. else
  291. {
  292. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  293. //GetSignature();
  294. StrAnnotToolChecked = "Signature";
  295. }
  296. }
  297. private void AddAnnotSignature(AnnotHandlerEventArgs annot)
  298. {
  299. if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
  300. (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
  301. if (StrAnnotToolChecked == "Signature")
  302. {
  303. if (viewContentViewModel.AnnotSignatures == null)
  304. viewContentViewModel.AnnotSignatures = new List<Tuple<int, int>>();
  305. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  306. if (signAnnot == null)
  307. {
  308. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
  309. }
  310. }
  311. }
  312. #endregion 与触发事件调用相关的函数
  313. #region PDFViewer事件
  314. private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
  315. //选中和非选中注释
  316. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  317. {
  318. if (e != null)
  319. {
  320. if (e.IsMouseRightActive)
  321. {
  322. ShowPropertyPanel(false);
  323. return;
  324. }
  325. CurrentSelectedAnnot = null;
  326. var annot = e.AnnotItemsList[0];
  327. if (annot != null)
  328. {
  329. if (e.AnnotItemsList.Count == 1)
  330. {
  331. //IsAnnotCreateReset:是否为创建注释的状态
  332. if (e.IsAnnotCreateReset == false)
  333. {
  334. GetSelectedAnnots(e);
  335. SelectedSignature(e.AnnotItemsList);
  336. CurrentSelectedAnnot = annot;
  337. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty
  338. && annot.EventType != AnnotArgsType.AnnotStamp && StrAnnotToolChecked != "Signature"
  339. && annot.EventType != AnnotArgsType.AnnotLink)
  340. {
  341. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  342. if (signAnnot == null)
  343. {
  344. ShowPropertyPanel(true);
  345. }
  346. }
  347. if (StrAnnotToolChecked == "Signature")
  348. {
  349. StrAnnotToolChecked = "";
  350. }
  351. }
  352. else
  353. {
  354. GetSelectedAnnots(e);
  355. PDFViewer.SetToolParam(annot);
  356. //switch (annot.EventType)
  357. //{
  358. // case AnnotArgsType.AnnotFreeText:
  359. // annot = GetFreetext(e.AnnotItemsList);
  360. // PDFViewer.SetToolParam(annot);
  361. // break;
  362. // case AnnotArgsType.AnnotSticky:
  363. // customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  364. // customStickyPopup.GetPDFViewer = PDFViewer;
  365. // propertyPanel.annot = e.AnnotItemsList[0];
  366. // var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  367. // propertyPanel.AnnotEvents = null;
  368. // propertyPanel.AnnotEvent = AnnotEvent;
  369. // propertyPanel.annotlists = e.AnnotItemsList;
  370. // break;
  371. // case AnnotArgsType.AnnotLink:
  372. // //viewContentViewModel.IsCreateLink = false;
  373. // GetLink(e.AnnotItemsList, e);
  374. // PDFViewer.SetToolParam(annot);
  375. // break;
  376. //}
  377. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  378. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  379. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  380. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  381. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  382. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  383. //annot.EventType != AnnotArgsType.AnnotLink &&
  384. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  385. //annot.EventType != AnnotArgsType.AnnotSticky &&
  386. //)
  387. //{
  388. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  389. // {
  390. // var strLineAnnotTag = "";
  391. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  392. // {
  393. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  394. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  395. // {
  396. // strLineAnnotTag = "Line";
  397. // }
  398. // else
  399. // {
  400. // strLineAnnotTag = "Arrow";
  401. // }
  402. // }
  403. // foreach (var item in ToolExpandDict)
  404. // {
  405. // if (item.Value == e.AnnotItemsList[0].EventType)
  406. // {
  407. // annot = null;//新建注释时,回到默认值
  408. // if (string.IsNullOrEmpty(strLineAnnotTag))
  409. // {
  410. // FindAnnotTypeKey(item.Key, ref annot);
  411. // break;
  412. // }
  413. // else
  414. // {
  415. // if (strLineAnnotTag == item.Key)
  416. // {
  417. // FindAnnotTypeKey(item.Key, ref annot);
  418. // break;
  419. // }
  420. // }
  421. // }
  422. // }
  423. // PDFViewer.SetToolParam(annot);
  424. // }
  425. //}
  426. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  427. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  428. //{
  429. // ShowPropertyPanel(false);
  430. //}
  431. //else
  432. //{
  433. // ShowPropertyPanel();
  434. //}
  435. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  436. }
  437. }
  438. else
  439. {
  440. bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  441. if (isDifferentAnnotTyle)
  442. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  443. else
  444. GetSelectedAnnots(e);
  445. }
  446. }
  447. //注释列表同步选中
  448. var list = e.GetPageAnnotsIndex();
  449. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  450. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  451. {
  452. if (list.Keys.Count == 0)
  453. {
  454. return;
  455. }
  456. var pageindex = new List<int>(list.Keys);
  457. List<int> annotes = new List<int>();
  458. list.TryGetValue(pageindex[0], out annotes);
  459. int annoteindex = annotes[0];
  460. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  461. if (viewModel != null)
  462. {
  463. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  464. }
  465. }
  466. }
  467. else
  468. {
  469. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  470. {
  471. return;
  472. }
  473. if (StrAnnotToolChecked == "Link")
  474. {
  475. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  476. {
  477. if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
  478. {
  479. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  480. }
  481. }
  482. }
  483. if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  484. {
  485. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  486. }
  487. }
  488. }
  489. //在注释工具的状态下,右键菜单
  490. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  491. {
  492. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  493. return;
  494. if ((UIElement)sender != null)
  495. {
  496. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  497. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  498. }
  499. switch (e.CommandType)
  500. {
  501. case CommandType.Context:
  502. if (e.AnnotEventArgsList.Count > 0)
  503. {
  504. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  505. {
  506. //绑定标记密文处右键菜单
  507. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  508. }
  509. else
  510. {
  511. if (e.AnnotEventArgsList.Count == 1)
  512. {
  513. var selectedAnnot = e.AnnotEventArgsList[0];
  514. PopMenuCheckedLineDash(selectedAnnot);
  515. PopMenuCheckedFontFamily(selectedAnnot);
  516. PopMenuCheckedTextAglin(selectedAnnot);
  517. switch (selectedAnnot.EventType)
  518. {
  519. case AnnotArgsType.AnnotHighlight:
  520. case AnnotArgsType.AnnotUnderline:
  521. case AnnotArgsType.AnnotStrikeout:
  522. case AnnotArgsType.AnnotSquiggly:
  523. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  524. {
  525. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  526. }
  527. else
  528. {
  529. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  530. }
  531. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  532. break;
  533. case AnnotArgsType.AnnotFreehand:
  534. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  535. break;
  536. case AnnotArgsType.AnnotFreeText:
  537. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  538. break;
  539. case AnnotArgsType.AnnotSticky:
  540. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  541. break;
  542. case AnnotArgsType.AnnotSquare:
  543. case AnnotArgsType.AnnotCircle:
  544. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  545. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  546. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  547. break;
  548. case AnnotArgsType.AnnotLine:
  549. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  550. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  551. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  552. break;
  553. case AnnotArgsType.AnnotLink:
  554. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  555. break;
  556. case AnnotArgsType.AnnotStamp:
  557. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  558. break;
  559. }
  560. }
  561. else
  562. {
  563. bool isHigh = true;//是否为高亮
  564. foreach (var item in e.AnnotEventArgsList)
  565. {
  566. if (AnnotTransfer.IsHightAnnot(item) == false)
  567. {
  568. isHigh = false;
  569. break;
  570. }
  571. }
  572. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  573. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  574. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  575. }
  576. }
  577. if (e.PopupMenu != null)
  578. {
  579. e.Handle = true;
  580. }
  581. }
  582. else
  583. {
  584. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  585. {
  586. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  587. if (e.PopupMenu != null)
  588. {
  589. e.Handle = true;
  590. }
  591. }
  592. else
  593. {
  594. e.PopupMenu = ViewerContextMenu(sender);
  595. if (e.PopupMenu != null)
  596. {
  597. e.Handle = true;
  598. }
  599. }
  600. }
  601. break;
  602. }
  603. }
  604. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  605. {
  606. if (e.Command == ApplicationCommands.Copy)
  607. {
  608. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
  609. if (result.IsDiscryptied)
  610. {
  611. if (result.Password != null)
  612. {
  613. string filePath = PDFViewer.Document.FilePath;
  614. var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
  615. }
  616. }
  617. else
  618. {
  619. e.Handled = true;
  620. }
  621. }
  622. }
  623. //右键菜单,选中字体样式按钮状态
  624. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  625. {
  626. if (annot != null)
  627. {
  628. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  629. {
  630. var freeText = annot as FreeTextAnnotArgs;
  631. FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
  632. }
  633. }
  634. }
  635. //右键菜单,选中文本内容对齐按钮状态
  636. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  637. {
  638. if (annot != null)
  639. {
  640. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  641. {
  642. var freeText = annot as FreeTextAnnotArgs;
  643. switch (freeText.Align)
  644. {
  645. case TextAlignment.Left:
  646. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  647. break;
  648. case TextAlignment.Center:
  649. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  650. break;
  651. case TextAlignment.Right:
  652. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  653. break;
  654. case TextAlignment.Justify:
  655. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  656. break;
  657. default:
  658. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  659. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  660. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  661. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  662. break;
  663. }
  664. }
  665. }
  666. }
  667. //右键菜单,选中虚实线按钮状态
  668. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  669. {
  670. if (annot != null)
  671. {
  672. bool isSolidLineDash = true;
  673. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  674. {
  675. var freeHand = annot as FreehandAnnotArgs;
  676. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  677. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  678. }
  679. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  680. {
  681. var square = annot as SquareAnnotArgs;
  682. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  683. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  684. }
  685. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  686. {
  687. var circle = annot as CircleAnnotArgs;
  688. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  689. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  690. }
  691. else if (annot.EventType == AnnotArgsType.AnnotLine)
  692. {
  693. var line = annot as LineAnnotArgs;
  694. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  695. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  696. }
  697. }
  698. }
  699. /// <summary>
  700. /// 内容选择工具
  701. /// </summary>
  702. /// <param name="sender"></param>
  703. /// <param name="e"></param>
  704. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  705. {
  706. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  707. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  708. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  709. SnapshotEditMenuViewModel.areaCropPageUndoManager = new AreaCropPageUndoManager(PDFViewer);
  710. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  711. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  712. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  713. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  714. {
  715. e.PopupMenu = popMenu;
  716. e.Handle = true;
  717. if (popMenu != null && popMenu.Items.Count == 5)
  718. {
  719. //复制
  720. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  721. menuItem.CommandTarget = PDFViewer;
  722. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  723. //导出
  724. menuItem = popMenu.Items[1] as MenuItem;
  725. menuItem.CommandTarget = PDFViewer;
  726. if (menuItem.Items.Count == 3)
  727. {
  728. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  729. menuItem1.CommandTarget = PDFViewer;
  730. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  731. menuItem1 = menuItem.Items[1] as MenuItem;
  732. menuItem1.CommandTarget = PDFViewer;
  733. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  734. menuItem1 = menuItem.Items[2] as MenuItem;
  735. menuItem1.CommandTarget = PDFViewer;
  736. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  737. }
  738. //裁剪
  739. menuItem = popMenu.Items[2] as MenuItem;
  740. menuItem.CommandTarget = PDFViewer;
  741. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  742. //缩放至所选区域
  743. menuItem = popMenu.Items[3] as MenuItem;
  744. menuItem.CommandTarget = PDFViewer;
  745. menuItem.Visibility = Visibility.Collapsed;
  746. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  747. //打印
  748. menuItem = popMenu.Items[4] as MenuItem;
  749. menuItem.CommandTarget = PDFViewer;
  750. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  751. }
  752. }
  753. }
  754. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  755. {
  756. switch (e.Key)
  757. {
  758. case "CloseSnap":
  759. {
  760. #region to do
  761. //var item = PDFViewerTab.SelectedItem as TabItem;
  762. //if (item == null)
  763. //{
  764. // ClearSelectedToolPanel();
  765. // return;
  766. //}
  767. //Grid grid = item.Content as Grid;
  768. //if (grid == null || grid.Children.Count == 0)
  769. //{
  770. // ClearSelectedToolPanel();
  771. // return;
  772. //}
  773. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  774. //if (pdfViewer == null)
  775. //{
  776. // ClearSelectedToolPanel();
  777. // return;
  778. //}
  779. #endregion to do
  780. switch (PDFViewer.MouseMode)
  781. {
  782. case MouseModes.SelectTextTool:
  783. break;
  784. default:
  785. BtnSelecttoolIsChecked = false;
  786. BtnHandIsChecked = true;
  787. PDFViewer.EnableZoom(true);
  788. PDFViewer.EnableScroll(true);
  789. break;
  790. }
  791. }
  792. break;
  793. default:
  794. break;
  795. }
  796. }
  797. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  798. {
  799. if (e != null && e.Count > 0)
  800. {
  801. MultipleSelectionAnnot(e);
  802. for (int i = 0; i < e.Count; i++)
  803. {
  804. AnnotEditEvent editEvent = e[i];
  805. switch (editEvent.EditAction)
  806. {
  807. case ActionType.Add:
  808. if (editEvent.EditAnnotArgs is StickyAnnotArgs stickyAnnotArgs)
  809. {
  810. PDFViewer.SelectAnnotation(stickyAnnotArgs.PageIndex, stickyAnnotArgs.AnnotIndex);
  811. }
  812. if (editEvent.EditAnnotArgs is FreeTextAnnotArgs freeTextAnnotArgs)
  813. {
  814. PDFViewer.SelectAnnotation(freeTextAnnotArgs.PageIndex, freeTextAnnotArgs.AnnotIndex);
  815. }
  816. //BOTA
  817. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  818. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  819. {
  820. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  821. if (viewModel != null)
  822. {
  823. int pageindex = editEvent.PageIndex;
  824. int annotindex = editEvent.AnnotIndex;
  825. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  826. }
  827. }
  828. //添加书签注释,用于未保存前跟图章手绘注释的区分
  829. if (StrAnnotToolChecked == "Signature")
  830. {
  831. AddAnnotSignature(editEvent.EditAnnotArgs);
  832. }
  833. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  834. //{
  835. // (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  836. //}
  837. break;
  838. case ActionType.Del:
  839. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  840. if (isTabItemAnnotation)
  841. {
  842. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  843. if (viewModel != null)
  844. {
  845. int pageindex = editEvent.PageIndex;
  846. int annotindex = editEvent.AnnotIndex;
  847. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  848. }
  849. }
  850. break;
  851. case ActionType.Modify:
  852. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  853. if (bOTAContent.TabItemAnnotation.IsSelected)
  854. {
  855. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  856. if (viewModel != null)
  857. {
  858. int pageindex = editEvent.PageIndex;
  859. int annotindex = editEvent.AnnotIndex;
  860. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  861. }
  862. }
  863. break;
  864. case ActionType.TextEdit:
  865. break;
  866. default:
  867. break;
  868. }
  869. }
  870. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  871. if (IsNoSelectMenu)
  872. {
  873. IsNoSelectMenu = false;
  874. PDFViewer.SetMouseMode(MouseModes.PanTool);
  875. }
  876. }
  877. }
  878. //复制多个注释,粘贴后,默认注释未选中状态
  879. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  880. {
  881. bool isAdd = false;
  882. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  883. foreach (var item in e)
  884. {
  885. if (item.EditAction == ActionType.Add /*|| item.EditAction == ActionType.Modify*/)
  886. {
  887. var annot = item.EditAnnotArgs;
  888. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  889. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
  890. {
  891. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  892. {
  893. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  894. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  895. }
  896. else
  897. {
  898. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  899. }
  900. isAdd = true;
  901. }
  902. }
  903. }
  904. if (isAdd)
  905. {
  906. PDFViewer.ClearSelectAnnots();
  907. if (StrAnnotToolChecked != "Signature")
  908. PDFViewer.SelectAnnotation(selectAnnotDicts);
  909. }
  910. }
  911. //阅读页悬浮相应
  912. /// <summary>
  913. /// 阅读页鼠标悬浮在注释上的虚线
  914. /// </summary>
  915. /// <param name="sender"></param>
  916. /// <param name="e"></param>
  917. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  918. {
  919. if (e != null && e.DrawContext != null)
  920. {
  921. Rect hoverRect = new Rect(
  922. e.PaintRect.Left - 2,
  923. e.PaintRect.Top - 2,
  924. e.PaintRect.Width + 4,
  925. e.PaintRect.Height + 4);
  926. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  927. hoverPen.DashStyle = DashStyles.Dash;
  928. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  929. //便签,显示ToolTip内容
  930. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  931. {
  932. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  933. return;
  934. }
  935. }
  936. CloseAnnotToolTip();
  937. }
  938. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  939. {
  940. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  941. {
  942. //鼠标移到注释之外,关闭ToolTip浮窗
  943. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  944. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  945. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  946. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  947. {
  948. CloseAnnotToolTip();
  949. }
  950. }
  951. }
  952. private Rect oldRect = new Rect(0, 0, 0, 0);
  953. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  954. {
  955. //便签,显示ToolTip内容
  956. if (PDFViewer.ToolTip == null)
  957. {
  958. if (string.IsNullOrEmpty(content) == false)
  959. {
  960. ToolTip TipChild = new ToolTip();
  961. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  962. TipChild.MaxWidth = 246;
  963. TipChild.Content = content;
  964. TipChild.Visibility = Visibility.Visible;
  965. TipChild.IsOpen = true;
  966. TipChild.Placement = PlacementMode.Right;
  967. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  968. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  969. TipChild.Placement = PlacementMode.MousePoint;
  970. PDFViewer.ToolTip = TipChild;
  971. oldRect = hoverRect;
  972. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  973. PDFViewer.MouseMove += PDFViewer_MouseMove;
  974. }
  975. }
  976. }
  977. //关闭ToolTip
  978. private void CloseAnnotToolTip()
  979. {
  980. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  981. {
  982. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  983. oldTips.IsOpen = false;
  984. oldTips.Visibility = Visibility.Collapsed;
  985. PDFViewer.ToolTip = null;
  986. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  987. oldRect = new Rect(0, 0, 0, 0);
  988. }
  989. }
  990. #endregion PDFViewer事件
  991. #region BindingEvent事件
  992. //同一属性面板,不同的注释类型
  993. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  994. {
  995. if (e != null)
  996. {
  997. AnnotHandlerEventArgs annotArgs = null;
  998. propertyPanel.SaveLastAnnot();
  999. foreach (AnnotArgsType argsType in e.Keys)
  1000. {
  1001. if (propertyPanel.annot.EventType != argsType)
  1002. {
  1003. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1004. }
  1005. switch (argsType)
  1006. {
  1007. case AnnotArgsType.AnnotSquare:
  1008. annotArgs = GetRect();
  1009. break;
  1010. case AnnotArgsType.AnnotCircle:
  1011. annotArgs = GetCircle();
  1012. break;
  1013. case AnnotArgsType.AnnotLine:
  1014. var LineTag = e[argsType] as string;
  1015. annotArgs = GetArrowLine(LineTag);
  1016. break;
  1017. }
  1018. ShowPropertyPanel();
  1019. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  1020. {
  1021. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1022. return;
  1023. }
  1024. if (annotArgs != null)
  1025. {
  1026. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1027. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1028. PDFViewer.SetToolParam(annotArgs);
  1029. }
  1030. }
  1031. }
  1032. }
  1033. //来自属性面板的事件,更改颜色等属性而触发
  1034. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1035. {
  1036. if (e != null)
  1037. {
  1038. foreach (AnnotArgsType argsType in e.Keys)
  1039. {
  1040. var key = ToolExpandDict.FirstOrDefault(q => q.Value == argsType);
  1041. switch (argsType)
  1042. {
  1043. case AnnotArgsType.AnnotHighlight:
  1044. if (e[argsType] is Color)
  1045. {
  1046. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  1047. }
  1048. if (e[argsType] is double)
  1049. {
  1050. HighLightOpacity = (double)e[argsType];
  1051. }
  1052. //创建注释后,修改注释属性,可用于下次创建的注释
  1053. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1054. {
  1055. if (StrAnnotToolChecked == key.Key)
  1056. {
  1057. PDFViewer.SetToolParam(propertyPanel.annot);
  1058. }
  1059. }
  1060. break;
  1061. case AnnotArgsType.AnnotUnderline:
  1062. if (e[argsType] is Color)
  1063. {
  1064. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1065. }
  1066. if (e[argsType] is double)
  1067. {
  1068. underLineOpacity = (double)e[argsType];
  1069. }
  1070. //创建注释后,修改注释属性,可用于下次创建的注释
  1071. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1072. {
  1073. if (StrAnnotToolChecked == key.Key)
  1074. {
  1075. PDFViewer.SetToolParam(propertyPanel.annot);
  1076. }
  1077. }
  1078. break;
  1079. case AnnotArgsType.AnnotSquiggly:
  1080. if (e[argsType] is Color)
  1081. {
  1082. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1083. }
  1084. if (e[argsType] is double)
  1085. {
  1086. SquigglyOpacity = (double)e[argsType];
  1087. }
  1088. //创建注释后,修改注释属性,可用于下次创建的注释
  1089. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1090. {
  1091. if (StrAnnotToolChecked == key.Key)
  1092. {
  1093. PDFViewer.SetToolParam(propertyPanel.annot);
  1094. }
  1095. }
  1096. break;
  1097. case AnnotArgsType.AnnotStrikeout:
  1098. if (e[argsType] is Color)
  1099. {
  1100. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1101. }
  1102. if (e[argsType] is double)
  1103. {
  1104. StrikeoutOpacity = (double)e[argsType];
  1105. }
  1106. //创建注释后,修改注释属性,可用于下次创建的注释
  1107. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1108. {
  1109. if (StrAnnotToolChecked == key.Key)
  1110. {
  1111. PDFViewer.SetToolParam(propertyPanel.annot);
  1112. }
  1113. }
  1114. break;
  1115. case AnnotArgsType.AnnotFreehand:
  1116. if (e[argsType] is FreehandAnnotArgs)
  1117. {
  1118. var annot = e[argsType] as FreehandAnnotArgs;
  1119. if (annot != null)
  1120. {
  1121. if (propertyPanel != null)
  1122. {
  1123. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1124. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1125. propertyPanel.AnnotEvent = AnnotEvent;
  1126. var AnnotEvents = new List<AnnotAttribEvent>();
  1127. AnnotEvents.Add(AnnotEvent);
  1128. propertyPanel.AnnotEvents = AnnotEvents;
  1129. propertyPanel.annot = annot;
  1130. //手绘注释工具按钮的属性
  1131. // FreehandPath.Opacity = annot.Transparency;
  1132. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1133. }
  1134. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1135. {
  1136. if (StrAnnotToolChecked == key.Key)
  1137. {
  1138. PDFViewer.SetToolParam(propertyPanel.annot);
  1139. }
  1140. }
  1141. }
  1142. }
  1143. break;
  1144. case AnnotArgsType.AnnotErase:
  1145. if (e[argsType] is ToggleButton)
  1146. {
  1147. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1148. if (clickBtn.IsChecked == true)
  1149. {
  1150. if (clickBtn.Tag.ToString() == "PenBtn")
  1151. {
  1152. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1153. btn.Tag = "Freehand"; btn.IsChecked = true;
  1154. BtnMyTools_Click(btn);
  1155. break;
  1156. }
  1157. CreateEraseArgs();
  1158. }
  1159. }
  1160. break;
  1161. case AnnotArgsType.AnnotSquare:
  1162. case AnnotArgsType.AnnotCircle:
  1163. case AnnotArgsType.AnnotLine:
  1164. case AnnotArgsType.AnnotFreeText:
  1165. //创建注释后,修改注释属性,可用于下次创建的注释
  1166. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1167. {
  1168. if (StrAnnotToolChecked == key.Key)
  1169. {
  1170. PDFViewer.SetToolParam(propertyPanel.annot);
  1171. }
  1172. }
  1173. break;
  1174. }
  1175. }
  1176. }
  1177. }
  1178. private void CreateEraseArgs()
  1179. {
  1180. EraseArgs eraseArgs = new EraseArgs();
  1181. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1182. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1183. eraseArgs.Thickness = 10;
  1184. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1185. if (annotProperty != null)
  1186. {
  1187. eraseArgs.Thickness = annotProperty.Thickness;
  1188. }
  1189. PDFViewer.ClearSelectAnnots(false);
  1190. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1191. PDFViewer.SetToolParam(eraseArgs);
  1192. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1193. if (eraseArgs != null)
  1194. eraseArgsList.Add(eraseArgs);
  1195. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1196. }
  1197. #endregion BindingEvent事件
  1198. }
  1199. }