AnnotToolContentViewModel.Command.cs 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  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 (e == null)
  324. {
  325. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  326. {
  327. //viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  328. return;
  329. }
  330. PropertyPanel.annot = null;
  331. PropertyPanel.AnnotEvents = null;
  332. PropertyPanel.AnnotEvent = null;
  333. PropertyPanel.annotlists = null;
  334. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  335. //HandToolIsCheckedEvent(false);
  336. if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  337. {
  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. ShowPropertyPanel(false);
  358. return;
  359. }
  360. CurrentSelectedAnnot = null;
  361. var annot = e.AnnotItemsList[0];
  362. if (annot != null)
  363. {
  364. if (e.AnnotItemsList.Count == 1)
  365. {
  366. //IsAnnotCreateReset:是否为创建注释的状态
  367. if (e.IsAnnotCreateReset == false)
  368. {
  369. CurrentSelectedAnnot = annot;
  370. GetSelectedAnnots(e);
  371. SelectedSignature(e.AnnotItemsList);
  372. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty
  373. && annot.EventType != AnnotArgsType.AnnotStamp && StrAnnotToolChecked != "Signature"
  374. && annot.EventType != AnnotArgsType.AnnotLink)
  375. {
  376. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  377. if (signAnnot == null)
  378. {
  379. ShowPropertyPanel(true);
  380. }
  381. }
  382. if (StrAnnotToolChecked == "Signature")
  383. {
  384. GetSignature();
  385. }
  386. //注释列表同步选中
  387. SelectedBotaAnnotationList(e);
  388. }
  389. else
  390. {
  391. if (!string.IsNullOrEmpty(StrAnnotToolChecked))
  392. {
  393. GetSelectedAnnots(e);
  394. PDFViewer.SetToolParam(annot);
  395. }
  396. else
  397. {
  398. PropertyPanel.annot = null;
  399. PropertyPanel.AnnotEvents = null;
  400. PropertyPanel.AnnotEvent = null;
  401. PropertyPanel.annotlists = null;
  402. PDFViewer.SetMouseMode(MouseModes.PanTool);
  403. HandToolIsCheckedEvent(false);
  404. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  405. }
  406. //switch (annot.EventType)
  407. //{
  408. // case AnnotArgsType.AnnotFreeText:
  409. // annot = GetFreetext(e.AnnotItemsList);
  410. // PDFViewer.SetToolParam(annot);
  411. // break;
  412. // case AnnotArgsType.AnnotSticky:
  413. // customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  414. // customStickyPopup.GetPDFViewer = PDFViewer;
  415. // propertyPanel.annot = e.AnnotItemsList[0];
  416. // var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  417. // propertyPanel.AnnotEvents = null;
  418. // propertyPanel.AnnotEvent = AnnotEvent;
  419. // propertyPanel.annotlists = e.AnnotItemsList;
  420. // break;
  421. // case AnnotArgsType.AnnotLink:
  422. // //viewContentViewModel.IsCreateLink = false;
  423. // GetLink(e.AnnotItemsList, e);
  424. // PDFViewer.SetToolParam(annot);
  425. // break;
  426. //}
  427. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  428. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  429. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  430. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  431. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  432. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  433. //annot.EventType != AnnotArgsType.AnnotLink &&
  434. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  435. //annot.EventType != AnnotArgsType.AnnotSticky &&
  436. //)
  437. //{
  438. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  439. // {
  440. // var strLineAnnotTag = "";
  441. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  442. // {
  443. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  444. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  445. // {
  446. // strLineAnnotTag = "Line";
  447. // }
  448. // else
  449. // {
  450. // strLineAnnotTag = "Arrow";
  451. // }
  452. // }
  453. // foreach (var item in ToolExpandDict)
  454. // {
  455. // if (item.Value == e.AnnotItemsList[0].EventType)
  456. // {
  457. // annot = null;//新建注释时,回到默认值
  458. // if (string.IsNullOrEmpty(strLineAnnotTag))
  459. // {
  460. // FindAnnotTypeKey(item.Key, ref annot);
  461. // break;
  462. // }
  463. // else
  464. // {
  465. // if (strLineAnnotTag == item.Key)
  466. // {
  467. // FindAnnotTypeKey(item.Key, ref annot);
  468. // break;
  469. // }
  470. // }
  471. // }
  472. // }
  473. // PDFViewer.SetToolParam(annot);
  474. // }
  475. //}
  476. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  477. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  478. //{
  479. // ShowPropertyPanel(false);
  480. //}
  481. //else
  482. //{
  483. // ShowPropertyPanel();
  484. //}
  485. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  486. }
  487. }
  488. else
  489. {
  490. bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  491. if (isDifferentAnnotTyle)
  492. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  493. else
  494. GetSelectedAnnots(e);
  495. }
  496. }
  497. }
  498. //else
  499. //{
  500. //if (StrAnnotToolChecked == "Link")
  501. //{
  502. // if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  503. // {
  504. // if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
  505. // {
  506. // viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  507. // }
  508. // }
  509. //}
  510. //if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  511. //{
  512. // viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  513. //}
  514. //}
  515. }
  516. /// <summary>
  517. /// 注释列表同步选中
  518. /// </summary>
  519. /// <param name="e"></param>
  520. private void SelectedBotaAnnotationList(AnnotAttribEvent e)
  521. {
  522. var list = e.GetPageAnnotsIndex();
  523. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  524. //if (viewContentViewModel.OpenBOTA == false || isTabItemAnnotation == false || bOTAContent.TabItemAnnotation.IsSelected == false)
  525. //{
  526. // viewContentViewModel.OpenBOTA = true;
  527. // bOTAContent.TabItemAnnotation.IsSelected = true;
  528. //}
  529. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  530. {
  531. if (list.Keys.Count == 0)
  532. {
  533. return;
  534. }
  535. var pageindex = new List<int>(list.Keys);
  536. List<int> annotes = new List<int>();
  537. list.TryGetValue(pageindex[0], out annotes);
  538. int annoteindex = annotes[0];
  539. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  540. if (viewModel != null)
  541. {
  542. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  543. }
  544. }
  545. }
  546. //在注释工具的状态下,右键菜单
  547. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  548. {
  549. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  550. return;
  551. if ((UIElement)sender != null)
  552. {
  553. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  554. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  555. }
  556. switch (e.CommandType)
  557. {
  558. case CommandType.Context:
  559. if (e.AnnotEventArgsList.Count > 0)
  560. {
  561. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  562. {
  563. //绑定标记密文处右键菜单
  564. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  565. }
  566. else
  567. {
  568. if (e.AnnotEventArgsList.Count == 1)
  569. {
  570. var selectedAnnot = e.AnnotEventArgsList[0];
  571. PopMenuCheckedLineDash(selectedAnnot);
  572. PopMenuCheckedFontFamily(selectedAnnot);
  573. PopMenuCheckedTextAglin(selectedAnnot);
  574. switch (selectedAnnot.EventType)
  575. {
  576. case AnnotArgsType.AnnotHighlight:
  577. case AnnotArgsType.AnnotUnderline:
  578. case AnnotArgsType.AnnotStrikeout:
  579. case AnnotArgsType.AnnotSquiggly:
  580. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  581. {
  582. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  583. }
  584. else
  585. {
  586. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  587. }
  588. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  589. break;
  590. case AnnotArgsType.AnnotFreehand:
  591. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  592. break;
  593. case AnnotArgsType.AnnotFreeText:
  594. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  595. break;
  596. case AnnotArgsType.AnnotSticky:
  597. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  598. break;
  599. case AnnotArgsType.AnnotSquare:
  600. case AnnotArgsType.AnnotCircle:
  601. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  602. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  603. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  604. break;
  605. case AnnotArgsType.AnnotLine:
  606. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  607. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  608. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  609. break;
  610. case AnnotArgsType.AnnotLink:
  611. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  612. break;
  613. case AnnotArgsType.AnnotStamp:
  614. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  615. break;
  616. }
  617. }
  618. else
  619. {
  620. bool isHigh = true;//是否为高亮
  621. foreach (var item in e.AnnotEventArgsList)
  622. {
  623. if (AnnotTransfer.IsHightAnnot(item) == false)
  624. {
  625. isHigh = false;
  626. break;
  627. }
  628. }
  629. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  630. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  631. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  632. }
  633. }
  634. if (e.PopupMenu != null)
  635. {
  636. e.Handle = true;
  637. }
  638. }
  639. else
  640. {
  641. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  642. {
  643. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  644. if (e.PopupMenu != null)
  645. {
  646. e.Handle = true;
  647. }
  648. }
  649. else
  650. {
  651. e.PopupMenu = ViewerContextMenu(sender);
  652. if (e.PopupMenu != null)
  653. {
  654. e.Handle = true;
  655. }
  656. }
  657. }
  658. break;
  659. }
  660. }
  661. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  662. {
  663. if (e.Command == ApplicationCommands.Copy)
  664. {
  665. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
  666. if (result.IsDiscryptied)
  667. {
  668. if (result.Password != null)
  669. {
  670. string filePath = PDFViewer.Document.FilePath;
  671. var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
  672. }
  673. }
  674. else
  675. {
  676. e.Handled = true;
  677. }
  678. }
  679. }
  680. //右键菜单,选中字体样式按钮状态
  681. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  682. {
  683. if (annot != null)
  684. {
  685. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  686. {
  687. var freeText = annot as FreeTextAnnotArgs;
  688. FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
  689. }
  690. }
  691. }
  692. //右键菜单,选中文本内容对齐按钮状态
  693. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  694. {
  695. if (annot != null)
  696. {
  697. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  698. {
  699. var freeText = annot as FreeTextAnnotArgs;
  700. switch (freeText.Align)
  701. {
  702. case TextAlignment.Left:
  703. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  704. break;
  705. case TextAlignment.Center:
  706. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  707. break;
  708. case TextAlignment.Right:
  709. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  710. break;
  711. case TextAlignment.Justify:
  712. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  713. break;
  714. default:
  715. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  716. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  717. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  718. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  719. break;
  720. }
  721. }
  722. }
  723. }
  724. //右键菜单,选中虚实线按钮状态
  725. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  726. {
  727. if (annot != null)
  728. {
  729. bool isSolidLineDash = true;
  730. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  731. {
  732. var freeHand = annot as FreehandAnnotArgs;
  733. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  734. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  735. }
  736. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  737. {
  738. var square = annot as SquareAnnotArgs;
  739. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  740. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  741. }
  742. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  743. {
  744. var circle = annot as CircleAnnotArgs;
  745. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  746. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  747. }
  748. else if (annot.EventType == AnnotArgsType.AnnotLine)
  749. {
  750. var line = annot as LineAnnotArgs;
  751. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  752. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  753. }
  754. }
  755. }
  756. /// <summary>
  757. /// 内容选择工具
  758. /// </summary>
  759. /// <param name="sender"></param>
  760. /// <param name="e"></param>
  761. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  762. {
  763. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  764. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  765. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  766. SnapshotEditMenuViewModel.areaCropPageUndoManager = new AreaCropPageUndoManager(PDFViewer);
  767. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  768. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  769. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  770. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  771. {
  772. e.PopupMenu = popMenu;
  773. e.Handle = true;
  774. if (popMenu != null && popMenu.Items.Count == 5)
  775. {
  776. //复制
  777. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  778. menuItem.CommandTarget = PDFViewer;
  779. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  780. //导出
  781. menuItem = popMenu.Items[1] as MenuItem;
  782. menuItem.CommandTarget = PDFViewer;
  783. if (menuItem.Items.Count == 3)
  784. {
  785. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  786. menuItem1.CommandTarget = PDFViewer;
  787. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  788. menuItem1 = menuItem.Items[1] as MenuItem;
  789. menuItem1.CommandTarget = PDFViewer;
  790. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  791. menuItem1 = menuItem.Items[2] as MenuItem;
  792. menuItem1.CommandTarget = PDFViewer;
  793. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  794. }
  795. //裁剪
  796. menuItem = popMenu.Items[2] as MenuItem;
  797. menuItem.CommandTarget = PDFViewer;
  798. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  799. //缩放至所选区域
  800. menuItem = popMenu.Items[3] as MenuItem;
  801. menuItem.CommandTarget = PDFViewer;
  802. menuItem.Visibility = Visibility.Collapsed;
  803. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  804. //打印
  805. menuItem = popMenu.Items[4] as MenuItem;
  806. menuItem.CommandTarget = PDFViewer;
  807. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  808. }
  809. }
  810. }
  811. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  812. {
  813. switch (e.Key)
  814. {
  815. case "CloseSnap":
  816. {
  817. #region to do
  818. //var item = PDFViewerTab.SelectedItem as TabItem;
  819. //if (item == null)
  820. //{
  821. // ClearSelectedToolPanel();
  822. // return;
  823. //}
  824. //Grid grid = item.Content as Grid;
  825. //if (grid == null || grid.Children.Count == 0)
  826. //{
  827. // ClearSelectedToolPanel();
  828. // return;
  829. //}
  830. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  831. //if (pdfViewer == null)
  832. //{
  833. // ClearSelectedToolPanel();
  834. // return;
  835. //}
  836. #endregion to do
  837. switch (PDFViewer.MouseMode)
  838. {
  839. case MouseModes.SelectTextTool:
  840. break;
  841. default:
  842. BtnSelecttoolIsChecked = false;
  843. //BtnHandIsChecked = true;
  844. PDFViewer.EnableZoom(true);
  845. PDFViewer.EnableScroll(true);
  846. PDFViewer.SetMouseMode(MouseModes.PanTool);
  847. break;
  848. }
  849. }
  850. break;
  851. default:
  852. break;
  853. }
  854. }
  855. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  856. {
  857. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  858. AnnotationContentViewModel viewModel = null;
  859. AnnotationContent annotation = null;
  860. if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  861. {
  862. viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out annotation);
  863. }
  864. bool isMultiple = false;
  865. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  866. if (e != null && e.Count > 0)
  867. {
  868. for (int i = 0; i < e.Count; i++)
  869. {
  870. AnnotEditEvent editEvent = e[i];
  871. bool isVisible = PDFViewer.CheckAnnotVisible(editEvent.PageIndex, editEvent.AnnotIndex);
  872. var annot = editEvent.EditAnnotArgs;
  873. switch (editEvent.EditAction)
  874. {
  875. case ActionType.Add:
  876. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  877. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText /*|| annot.EventType == AnnotArgsType.AnnotFreehand*/)
  878. {
  879. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  880. {
  881. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  882. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  883. }
  884. else
  885. {
  886. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  887. }
  888. isMultiple = true;
  889. }
  890. //if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  891. //{
  892. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  893. if (viewModel != null)
  894. {
  895. int pageindex = editEvent.PageIndex;
  896. int annotindex = editEvent.AnnotIndex;
  897. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  898. }
  899. //}
  900. //添加书签注释,用于未保存前跟图章手绘注释的区分
  901. if (StrAnnotToolChecked == "Signature")
  902. {
  903. AddAnnotSignature(editEvent.EditAnnotArgs);
  904. }
  905. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  906. //{
  907. // (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  908. //}
  909. break;
  910. case ActionType.Modify:
  911. // if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  912. //annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand)
  913. // {
  914. // if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  915. // {
  916. // selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  917. // selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  918. // }
  919. // else
  920. // {
  921. // selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  922. // }
  923. // isMultiple = true;
  924. // }
  925. if (viewModel != null)
  926. {
  927. int pageindex = editEvent.PageIndex;
  928. int annotindex = editEvent.AnnotIndex;
  929. viewModel.UpdateModifiedAnnot(pageindex, annotindex);
  930. }
  931. //}
  932. break;
  933. case ActionType.Del:
  934. //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  935. //if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  936. //{
  937. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  938. if (viewModel != null)
  939. {
  940. int pageindex = editEvent.PageIndex;
  941. int annotindex = editEvent.AnnotIndex;
  942. viewModel.DeleteModifiedAnnot(pageindex, annotindex);
  943. }
  944. //}
  945. ExitAnnotationTool();
  946. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  947. break;
  948. case ActionType.TextEdit:
  949. break;
  950. default:
  951. break;
  952. }
  953. }
  954. if (isMultiple && selectAnnotDicts.Count >= 1)
  955. {
  956. PDFViewer.ClearSelectAnnots();
  957. if (StrAnnotToolChecked != "Signature")
  958. {
  959. PDFViewer.SelectAnnotation(selectAnnotDicts);
  960. //foreach (var item in selectAnnotDicts.Keys)
  961. //{
  962. // List<int> value = selectAnnotDicts[item];
  963. // foreach (var item1 in value)
  964. // {
  965. // }
  966. //}
  967. }
  968. }
  969. //MultipleSelectionAnnot(e);
  970. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  971. if (IsNoSelectMenu)
  972. {
  973. IsNoSelectMenu = false;
  974. PDFViewer.SetMouseMode(MouseModes.PanTool);
  975. }
  976. }
  977. }
  978. //复制多个注释,粘贴后,默认注释未选中状态
  979. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  980. {
  981. bool isAdd = false;
  982. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  983. foreach (var item in e)
  984. {
  985. if (item.EditAction == ActionType.Add || item.EditAction == ActionType.Modify)
  986. {
  987. var annot = item.EditAnnotArgs;
  988. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  989. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand)
  990. {
  991. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  992. {
  993. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  994. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  995. }
  996. else
  997. {
  998. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  999. }
  1000. isAdd = true;
  1001. }
  1002. }
  1003. }
  1004. if (isAdd && selectAnnotDicts.Count >= 1)
  1005. {
  1006. PDFViewer.ClearSelectAnnots();
  1007. if (StrAnnotToolChecked != "Signature")
  1008. {
  1009. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1010. }
  1011. }
  1012. }
  1013. //阅读页悬浮相应
  1014. /// <summary>
  1015. /// 阅读页鼠标悬浮在注释上的虚线
  1016. /// </summary>
  1017. /// <param name="sender"></param>
  1018. /// <param name="e"></param>
  1019. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1020. {
  1021. if (e != null && e.DrawContext != null)
  1022. {
  1023. if (StrAnnotToolChecked != "Link")
  1024. {
  1025. if (e.Annot is CPDFLinkAnnotation linkAnnotation)
  1026. {
  1027. return;
  1028. }
  1029. }
  1030. Rect hoverRect = new Rect(
  1031. e.PaintRect.Left - 2,
  1032. e.PaintRect.Top - 2,
  1033. e.PaintRect.Width + 4,
  1034. e.PaintRect.Height + 4);
  1035. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1036. hoverPen.DashStyle = DashStyles.Dash;
  1037. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1038. //便签,显示ToolTip内容
  1039. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  1040. {
  1041. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  1042. return;
  1043. }
  1044. }
  1045. CloseAnnotToolTip();
  1046. }
  1047. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1048. {
  1049. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1050. {
  1051. //鼠标移到注释之外,关闭ToolTip浮窗
  1052. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1053. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1054. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1055. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1056. {
  1057. CloseAnnotToolTip();
  1058. }
  1059. }
  1060. }
  1061. private Rect oldRect = new Rect(0, 0, 0, 0);
  1062. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  1063. {
  1064. //便签,显示ToolTip内容
  1065. if (PDFViewer.ToolTip == null)
  1066. {
  1067. if (string.IsNullOrEmpty(content) == false)
  1068. {
  1069. ToolTip TipChild = new ToolTip();
  1070. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  1071. TipChild.MaxWidth = 246;
  1072. TipChild.Content = content;
  1073. TipChild.Visibility = Visibility.Visible;
  1074. TipChild.IsOpen = true;
  1075. TipChild.Placement = PlacementMode.Right;
  1076. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  1077. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1078. TipChild.Placement = PlacementMode.MousePoint;
  1079. PDFViewer.ToolTip = TipChild;
  1080. oldRect = hoverRect;
  1081. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1082. PDFViewer.MouseMove += PDFViewer_MouseMove;
  1083. }
  1084. }
  1085. }
  1086. //关闭ToolTip
  1087. private void CloseAnnotToolTip()
  1088. {
  1089. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1090. {
  1091. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1092. oldTips.IsOpen = false;
  1093. oldTips.Visibility = Visibility.Collapsed;
  1094. PDFViewer.ToolTip = null;
  1095. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1096. oldRect = new Rect(0, 0, 0, 0);
  1097. }
  1098. }
  1099. #endregion PDFViewer事件
  1100. #region BindingEvent事件
  1101. //同一属性面板,不同的注释类型
  1102. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1103. {
  1104. if (e != null && sender is SharpsAnnotPropertyViewModel sharpsAnnot)
  1105. {
  1106. AnnotHandlerEventArgs annotArgs = null;
  1107. //PropertyPanel.SaveLastAnnot();
  1108. List<AnnotHandlerEventArgs> annots = new List<AnnotHandlerEventArgs>();
  1109. foreach (AnnotArgsType argsType in e.Keys)
  1110. {
  1111. if (PropertyPanel.annot != null)
  1112. {
  1113. if (PropertyPanel.annot.EventType != argsType)
  1114. {
  1115. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1116. }
  1117. }
  1118. switch (argsType)
  1119. {
  1120. case AnnotArgsType.AnnotSquare:
  1121. if (CurrentSelectedAnnot != null)
  1122. {
  1123. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotSquare)
  1124. annots.Add(CurrentSelectedAnnot);
  1125. }
  1126. if (annots.Count > 0)
  1127. {
  1128. annotArgs = GetRect(annots);
  1129. }
  1130. else
  1131. {
  1132. annotArgs = GetRect();
  1133. }
  1134. break;
  1135. case AnnotArgsType.AnnotCircle:
  1136. if (CurrentSelectedAnnot != null)
  1137. {
  1138. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotCircle)
  1139. annots.Add(CurrentSelectedAnnot);
  1140. }
  1141. if (annots.Count > 0)
  1142. {
  1143. annotArgs = GetCircle(annots);
  1144. }
  1145. else
  1146. {
  1147. annotArgs = GetCircle();
  1148. }
  1149. break;
  1150. case AnnotArgsType.AnnotLine:
  1151. var LineTag = e[argsType] as string;
  1152. if (CurrentSelectedAnnot != null)
  1153. {
  1154. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotLine)
  1155. {
  1156. if (CurrentSelectedAnnot is LineAnnotArgs lineAnnotArgs)
  1157. {
  1158. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  1159. {
  1160. if (LineTag == "Arrow")
  1161. {
  1162. annots.Add(CurrentSelectedAnnot);
  1163. }
  1164. }
  1165. else
  1166. {
  1167. if (LineTag == "Line")
  1168. {
  1169. annots.Add(CurrentSelectedAnnot);
  1170. }
  1171. }
  1172. }
  1173. }
  1174. }
  1175. if (annots.Count > 0)
  1176. {
  1177. annotArgs = GetArrowLine(LineTag, annots);
  1178. }
  1179. else
  1180. {
  1181. annotArgs = GetArrowLine(LineTag);
  1182. }
  1183. break;
  1184. }
  1185. ShowPropertyPanel();
  1186. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  1187. {
  1188. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1189. return;
  1190. }
  1191. if (annotArgs != null)
  1192. {
  1193. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1194. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1195. PDFViewer.SetToolParam(annotArgs);
  1196. }
  1197. }
  1198. }
  1199. }
  1200. //来自属性面板的事件,更改颜色等属性而触发
  1201. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1202. {
  1203. if (e != null)
  1204. {
  1205. foreach (AnnotArgsType argsType in e.Keys)
  1206. {
  1207. var key = ToolExpandDict.FirstOrDefault(q => q.Value == argsType);
  1208. switch (argsType)
  1209. {
  1210. case AnnotArgsType.AnnotHighlight:
  1211. if (e[argsType] is Color)
  1212. {
  1213. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  1214. }
  1215. if (e[argsType] is double)
  1216. {
  1217. HighLightOpacity = (double)e[argsType];
  1218. }
  1219. //创建注释后,修改注释属性,可用于下次创建的注释
  1220. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1221. {
  1222. if (StrAnnotToolChecked == key.Key)
  1223. {
  1224. PDFViewer.SetToolParam(PropertyPanel.annot);
  1225. }
  1226. }
  1227. break;
  1228. case AnnotArgsType.AnnotUnderline:
  1229. if (e[argsType] is Color)
  1230. {
  1231. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1232. }
  1233. if (e[argsType] is double)
  1234. {
  1235. underLineOpacity = (double)e[argsType];
  1236. }
  1237. //创建注释后,修改注释属性,可用于下次创建的注释
  1238. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1239. {
  1240. if (StrAnnotToolChecked == key.Key)
  1241. {
  1242. PDFViewer.SetToolParam(PropertyPanel.annot);
  1243. }
  1244. }
  1245. break;
  1246. case AnnotArgsType.AnnotSquiggly:
  1247. if (e[argsType] is Color)
  1248. {
  1249. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1250. }
  1251. if (e[argsType] is double)
  1252. {
  1253. SquigglyOpacity = (double)e[argsType];
  1254. }
  1255. //创建注释后,修改注释属性,可用于下次创建的注释
  1256. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1257. {
  1258. if (StrAnnotToolChecked == key.Key)
  1259. {
  1260. PDFViewer.SetToolParam(PropertyPanel.annot);
  1261. }
  1262. }
  1263. break;
  1264. case AnnotArgsType.AnnotStrikeout:
  1265. if (e[argsType] is Color)
  1266. {
  1267. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1268. }
  1269. if (e[argsType] is double)
  1270. {
  1271. StrikeoutOpacity = (double)e[argsType];
  1272. }
  1273. //创建注释后,修改注释属性,可用于下次创建的注释
  1274. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1275. {
  1276. if (StrAnnotToolChecked == key.Key)
  1277. {
  1278. PDFViewer.SetToolParam(PropertyPanel.annot);
  1279. }
  1280. }
  1281. break;
  1282. case AnnotArgsType.AnnotFreehand:
  1283. if (e[argsType] is FreehandAnnotArgs)
  1284. {
  1285. var annot = e[argsType] as FreehandAnnotArgs;
  1286. if (annot != null)
  1287. {
  1288. if (PropertyPanel != null)
  1289. {
  1290. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1291. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1292. PropertyPanel.AnnotEvent = AnnotEvent;
  1293. var AnnotEvents = new List<AnnotAttribEvent>();
  1294. AnnotEvents.Add(AnnotEvent);
  1295. PropertyPanel.AnnotEvents = AnnotEvents;
  1296. PropertyPanel.annot = annot;
  1297. //手绘注释工具按钮的属性
  1298. // FreehandPath.Opacity = annot.Transparency;
  1299. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1300. }
  1301. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1302. {
  1303. if (StrAnnotToolChecked == key.Key)
  1304. {
  1305. PDFViewer.SetToolParam(PropertyPanel.annot);
  1306. }
  1307. }
  1308. }
  1309. }
  1310. break;
  1311. case AnnotArgsType.AnnotErase:
  1312. if (e[argsType] is ToggleButton)
  1313. {
  1314. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1315. if (clickBtn.IsChecked == true)
  1316. {
  1317. if (clickBtn.Tag.ToString() == "PenBtn")
  1318. {
  1319. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1320. btn.Tag = "Freehand"; btn.IsChecked = true;
  1321. BtnMyTools_Click(btn);
  1322. break;
  1323. }
  1324. CreateEraseArgs();
  1325. }
  1326. }
  1327. break;
  1328. case AnnotArgsType.AnnotSquare:
  1329. case AnnotArgsType.AnnotCircle:
  1330. case AnnotArgsType.AnnotLine:
  1331. case AnnotArgsType.AnnotFreeText:
  1332. //创建注释后,修改注释属性,可用于下次创建的注释
  1333. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1334. {
  1335. if (StrAnnotToolChecked == key.Key || PropertyPanel.SharpsAnnot == key.Key)
  1336. {
  1337. PDFViewer.SetToolParam(PropertyPanel.annot);
  1338. PropertyPanel.SaveLastAnnot();
  1339. }
  1340. }
  1341. break;
  1342. }
  1343. }
  1344. }
  1345. }
  1346. private void CreateEraseArgs()
  1347. {
  1348. EraseArgs eraseArgs = new EraseArgs();
  1349. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1350. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1351. eraseArgs.Thickness = 10;
  1352. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1353. if (annotProperty != null)
  1354. {
  1355. eraseArgs.Thickness = annotProperty.Thickness;
  1356. }
  1357. PDFViewer.ClearSelectAnnots(false);
  1358. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1359. PDFViewer.SetToolParam(eraseArgs);
  1360. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1361. if (eraseArgs != null)
  1362. eraseArgsList.Add(eraseArgs);
  1363. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1364. }
  1365. #endregion BindingEvent事件
  1366. }
  1367. }