AnnotToolContentViewModel.Command.cs 63 KB

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