AnnotToolContentViewModel.Command.cs 73 KB

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