AnnotToolContentViewModel.Command.cs 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. return;
  473. }
  474. if (StrAnnotToolChecked == "Link")
  475. {
  476. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  477. {
  478. if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
  479. {
  480. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  481. }
  482. }
  483. }
  484. if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  485. {
  486. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  487. }
  488. }
  489. }
  490. //在注释工具的状态下,右键菜单
  491. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  492. {
  493. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  494. return;
  495. if ((UIElement)sender != null)
  496. {
  497. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  498. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  499. }
  500. switch (e.CommandType)
  501. {
  502. case CommandType.Context:
  503. if (e.AnnotEventArgsList.Count > 0)
  504. {
  505. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  506. {
  507. //绑定标记密文处右键菜单
  508. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  509. }
  510. else
  511. {
  512. if (e.AnnotEventArgsList.Count == 1)
  513. {
  514. var selectedAnnot = e.AnnotEventArgsList[0];
  515. PopMenuCheckedLineDash(selectedAnnot);
  516. PopMenuCheckedFontFamily(selectedAnnot);
  517. PopMenuCheckedTextAglin(selectedAnnot);
  518. switch (selectedAnnot.EventType)
  519. {
  520. case AnnotArgsType.AnnotHighlight:
  521. case AnnotArgsType.AnnotUnderline:
  522. case AnnotArgsType.AnnotStrikeout:
  523. case AnnotArgsType.AnnotSquiggly:
  524. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  525. {
  526. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  527. }
  528. else
  529. {
  530. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  531. }
  532. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  533. break;
  534. case AnnotArgsType.AnnotFreehand:
  535. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  536. break;
  537. case AnnotArgsType.AnnotFreeText:
  538. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  539. break;
  540. case AnnotArgsType.AnnotSticky:
  541. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  542. break;
  543. case AnnotArgsType.AnnotSquare:
  544. case AnnotArgsType.AnnotCircle:
  545. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  546. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  547. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  548. break;
  549. case AnnotArgsType.AnnotLine:
  550. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  551. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  552. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  553. break;
  554. case AnnotArgsType.AnnotLink:
  555. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  556. break;
  557. case AnnotArgsType.AnnotStamp:
  558. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  559. break;
  560. }
  561. }
  562. else
  563. {
  564. bool isHigh = true;//是否为高亮
  565. foreach (var item in e.AnnotEventArgsList)
  566. {
  567. if (AnnotTransfer.IsHightAnnot(item) == false)
  568. {
  569. isHigh = false;
  570. break;
  571. }
  572. }
  573. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  574. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  575. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  576. }
  577. }
  578. if (e.PopupMenu != null)
  579. {
  580. e.Handle = true;
  581. }
  582. }
  583. else
  584. {
  585. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  586. {
  587. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  588. if (e.PopupMenu != null)
  589. {
  590. e.Handle = true;
  591. }
  592. }
  593. else
  594. {
  595. e.PopupMenu = ViewerContextMenu(sender);
  596. if (e.PopupMenu != null)
  597. {
  598. e.Handle = true;
  599. }
  600. }
  601. }
  602. break;
  603. }
  604. }
  605. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  606. {
  607. if (e.Command == ApplicationCommands.Copy)
  608. {
  609. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
  610. if (result.IsDiscryptied)
  611. {
  612. if (result.Password != null)
  613. {
  614. string filePath = PDFViewer.Document.FilePath;
  615. var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
  616. }
  617. }
  618. else
  619. {
  620. e.Handled = true;
  621. }
  622. }
  623. }
  624. //右键菜单,选中字体样式按钮状态
  625. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  626. {
  627. if (annot != null)
  628. {
  629. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  630. {
  631. var freeText = annot as FreeTextAnnotArgs;
  632. FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
  633. }
  634. }
  635. }
  636. //右键菜单,选中文本内容对齐按钮状态
  637. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  638. {
  639. if (annot != null)
  640. {
  641. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  642. {
  643. var freeText = annot as FreeTextAnnotArgs;
  644. switch (freeText.Align)
  645. {
  646. case TextAlignment.Left:
  647. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  648. break;
  649. case TextAlignment.Center:
  650. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  651. break;
  652. case TextAlignment.Right:
  653. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  654. break;
  655. case TextAlignment.Justify:
  656. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  657. break;
  658. default:
  659. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  660. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  661. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  662. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  663. break;
  664. }
  665. }
  666. }
  667. }
  668. //右键菜单,选中虚实线按钮状态
  669. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  670. {
  671. if (annot != null)
  672. {
  673. bool isSolidLineDash = true;
  674. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  675. {
  676. var freeHand = annot as FreehandAnnotArgs;
  677. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  678. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  679. }
  680. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  681. {
  682. var square = annot as SquareAnnotArgs;
  683. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  684. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  685. }
  686. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  687. {
  688. var circle = annot as CircleAnnotArgs;
  689. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  690. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  691. }
  692. else if (annot.EventType == AnnotArgsType.AnnotLine)
  693. {
  694. var line = annot as LineAnnotArgs;
  695. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  696. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  697. }
  698. }
  699. }
  700. /// <summary>
  701. /// 内容选择工具
  702. /// </summary>
  703. /// <param name="sender"></param>
  704. /// <param name="e"></param>
  705. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  706. {
  707. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  708. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  709. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  710. SnapshotEditMenuViewModel.areaCropPageUndoManager = new AreaCropPageUndoManager(PDFViewer);
  711. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  712. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  713. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  714. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  715. {
  716. e.PopupMenu = popMenu;
  717. e.Handle = true;
  718. if (popMenu != null && popMenu.Items.Count == 5)
  719. {
  720. //复制
  721. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  722. menuItem.CommandTarget = PDFViewer;
  723. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  724. //导出
  725. menuItem = popMenu.Items[1] as MenuItem;
  726. menuItem.CommandTarget = PDFViewer;
  727. if (menuItem.Items.Count == 3)
  728. {
  729. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  730. menuItem1.CommandTarget = PDFViewer;
  731. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  732. menuItem1 = menuItem.Items[1] as MenuItem;
  733. menuItem1.CommandTarget = PDFViewer;
  734. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  735. menuItem1 = menuItem.Items[2] as MenuItem;
  736. menuItem1.CommandTarget = PDFViewer;
  737. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  738. }
  739. //裁剪
  740. menuItem = popMenu.Items[2] as MenuItem;
  741. menuItem.CommandTarget = PDFViewer;
  742. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  743. //缩放至所选区域
  744. menuItem = popMenu.Items[3] as MenuItem;
  745. menuItem.CommandTarget = PDFViewer;
  746. menuItem.Visibility = Visibility.Collapsed;
  747. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  748. //打印
  749. menuItem = popMenu.Items[4] as MenuItem;
  750. menuItem.CommandTarget = PDFViewer;
  751. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  752. }
  753. }
  754. }
  755. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  756. {
  757. switch (e.Key)
  758. {
  759. case "CloseSnap":
  760. {
  761. #region to do
  762. //var item = PDFViewerTab.SelectedItem as TabItem;
  763. //if (item == null)
  764. //{
  765. // ClearSelectedToolPanel();
  766. // return;
  767. //}
  768. //Grid grid = item.Content as Grid;
  769. //if (grid == null || grid.Children.Count == 0)
  770. //{
  771. // ClearSelectedToolPanel();
  772. // return;
  773. //}
  774. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  775. //if (pdfViewer == null)
  776. //{
  777. // ClearSelectedToolPanel();
  778. // return;
  779. //}
  780. #endregion to do
  781. switch (PDFViewer.MouseMode)
  782. {
  783. case MouseModes.SelectTextTool:
  784. break;
  785. default:
  786. BtnSelecttoolIsChecked = false;
  787. BtnHandIsChecked = true;
  788. PDFViewer.EnableZoom(true);
  789. PDFViewer.EnableScroll(true);
  790. break;
  791. }
  792. }
  793. break;
  794. default:
  795. break;
  796. }
  797. }
  798. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  799. {
  800. if (e != null && e.Count > 0)
  801. {
  802. MultipleSelectionAnnot(e);
  803. for (int i = 0; i < e.Count; i++)
  804. {
  805. AnnotEditEvent editEvent = e[i];
  806. switch (editEvent.EditAction)
  807. {
  808. case ActionType.Add:
  809. if (editEvent.EditAnnotArgs is StickyAnnotArgs stickyAnnotArgs)
  810. {
  811. PDFViewer.SelectAnnotation(stickyAnnotArgs.PageIndex, stickyAnnotArgs.AnnotIndex);
  812. }
  813. if (editEvent.EditAnnotArgs is FreeTextAnnotArgs freeTextAnnotArgs)
  814. {
  815. PDFViewer.SelectAnnotation(freeTextAnnotArgs.PageIndex, freeTextAnnotArgs.AnnotIndex);
  816. }
  817. //BOTA
  818. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  819. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  820. {
  821. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  822. if (viewModel != null)
  823. {
  824. int pageindex = editEvent.PageIndex;
  825. int annotindex = editEvent.AnnotIndex;
  826. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  827. }
  828. }
  829. //添加书签注释,用于未保存前跟图章手绘注释的区分
  830. if (StrAnnotToolChecked == "Signature")
  831. {
  832. AddAnnotSignature(editEvent.EditAnnotArgs);
  833. }
  834. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  835. //{
  836. // (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  837. //}
  838. break;
  839. case ActionType.Del:
  840. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  841. if (isTabItemAnnotation)
  842. {
  843. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  844. if (viewModel != null)
  845. {
  846. int pageindex = editEvent.PageIndex;
  847. int annotindex = editEvent.AnnotIndex;
  848. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  849. }
  850. }
  851. break;
  852. case ActionType.Modify:
  853. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  854. if (bOTAContent.TabItemAnnotation.IsSelected)
  855. {
  856. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  857. if (viewModel != null)
  858. {
  859. int pageindex = editEvent.PageIndex;
  860. int annotindex = editEvent.AnnotIndex;
  861. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  862. }
  863. }
  864. break;
  865. case ActionType.TextEdit:
  866. break;
  867. default:
  868. break;
  869. }
  870. }
  871. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  872. if (IsNoSelectMenu)
  873. {
  874. IsNoSelectMenu = false;
  875. PDFViewer.SetMouseMode(MouseModes.PanTool);
  876. }
  877. }
  878. }
  879. //复制多个注释,粘贴后,默认注释未选中状态
  880. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  881. {
  882. bool isAdd = false;
  883. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  884. foreach (var item in e)
  885. {
  886. if (item.EditAction == ActionType.Add /*|| item.EditAction == ActionType.Modify*/)
  887. {
  888. var annot = item.EditAnnotArgs;
  889. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  890. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
  891. {
  892. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  893. {
  894. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  895. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  896. }
  897. else
  898. {
  899. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  900. }
  901. isAdd = true;
  902. }
  903. }
  904. }
  905. if (isAdd)
  906. {
  907. PDFViewer.ClearSelectAnnots();
  908. if (StrAnnotToolChecked != "Signature")
  909. PDFViewer.SelectAnnotation(selectAnnotDicts);
  910. }
  911. }
  912. //阅读页悬浮相应
  913. /// <summary>
  914. /// 阅读页鼠标悬浮在注释上的虚线
  915. /// </summary>
  916. /// <param name="sender"></param>
  917. /// <param name="e"></param>
  918. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  919. {
  920. if (e != null && e.DrawContext != null)
  921. {
  922. Rect hoverRect = new Rect(
  923. e.PaintRect.Left - 2,
  924. e.PaintRect.Top - 2,
  925. e.PaintRect.Width + 4,
  926. e.PaintRect.Height + 4);
  927. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  928. hoverPen.DashStyle = DashStyles.Dash;
  929. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  930. //便签,显示ToolTip内容
  931. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  932. {
  933. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  934. return;
  935. }
  936. }
  937. CloseAnnotToolTip();
  938. }
  939. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  940. {
  941. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  942. {
  943. //鼠标移到注释之外,关闭ToolTip浮窗
  944. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  945. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  946. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  947. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  948. {
  949. CloseAnnotToolTip();
  950. }
  951. }
  952. }
  953. private Rect oldRect = new Rect(0, 0, 0, 0);
  954. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  955. {
  956. //便签,显示ToolTip内容
  957. if (PDFViewer.ToolTip == null)
  958. {
  959. if (string.IsNullOrEmpty(content) == false)
  960. {
  961. ToolTip TipChild = new ToolTip();
  962. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  963. TipChild.MaxWidth = 246;
  964. TipChild.Content = content;
  965. TipChild.Visibility = Visibility.Visible;
  966. TipChild.IsOpen = true;
  967. TipChild.Placement = PlacementMode.Right;
  968. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  969. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  970. TipChild.Placement = PlacementMode.MousePoint;
  971. PDFViewer.ToolTip = TipChild;
  972. oldRect = hoverRect;
  973. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  974. PDFViewer.MouseMove += PDFViewer_MouseMove;
  975. }
  976. }
  977. }
  978. //关闭ToolTip
  979. private void CloseAnnotToolTip()
  980. {
  981. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  982. {
  983. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  984. oldTips.IsOpen = false;
  985. oldTips.Visibility = Visibility.Collapsed;
  986. PDFViewer.ToolTip = null;
  987. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  988. oldRect = new Rect(0, 0, 0, 0);
  989. }
  990. }
  991. #endregion PDFViewer事件
  992. #region BindingEvent事件
  993. //同一属性面板,不同的注释类型
  994. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  995. {
  996. if (e != null)
  997. {
  998. AnnotHandlerEventArgs annotArgs = null;
  999. propertyPanel.SaveLastAnnot();
  1000. foreach (AnnotArgsType argsType in e.Keys)
  1001. {
  1002. if (propertyPanel.annot.EventType != argsType)
  1003. {
  1004. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1005. }
  1006. switch (argsType)
  1007. {
  1008. case AnnotArgsType.AnnotSquare:
  1009. annotArgs = GetRect();
  1010. break;
  1011. case AnnotArgsType.AnnotCircle:
  1012. annotArgs = GetCircle();
  1013. break;
  1014. case AnnotArgsType.AnnotLine:
  1015. var LineTag = e[argsType] as string;
  1016. annotArgs = GetArrowLine(LineTag);
  1017. break;
  1018. }
  1019. ShowPropertyPanel();
  1020. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  1021. {
  1022. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1023. return;
  1024. }
  1025. if (annotArgs != null)
  1026. {
  1027. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1028. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1029. PDFViewer.SetToolParam(annotArgs);
  1030. }
  1031. }
  1032. }
  1033. }
  1034. //来自属性面板的事件,更改颜色等属性而触发
  1035. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1036. {
  1037. if (e != null)
  1038. {
  1039. foreach (AnnotArgsType argsType in e.Keys)
  1040. {
  1041. var key = ToolExpandDict.FirstOrDefault(q => q.Value == argsType);
  1042. switch (argsType)
  1043. {
  1044. case AnnotArgsType.AnnotHighlight:
  1045. if (e[argsType] is Color)
  1046. {
  1047. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  1048. }
  1049. if (e[argsType] is double)
  1050. {
  1051. HighLightOpacity = (double)e[argsType];
  1052. }
  1053. //创建注释后,修改注释属性,可用于下次创建的注释
  1054. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1055. {
  1056. if (StrAnnotToolChecked == key.Key)
  1057. {
  1058. PDFViewer.SetToolParam(propertyPanel.annot);
  1059. }
  1060. }
  1061. break;
  1062. case AnnotArgsType.AnnotUnderline:
  1063. if (e[argsType] is Color)
  1064. {
  1065. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1066. }
  1067. if (e[argsType] is double)
  1068. {
  1069. underLineOpacity = (double)e[argsType];
  1070. }
  1071. //创建注释后,修改注释属性,可用于下次创建的注释
  1072. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1073. {
  1074. if (StrAnnotToolChecked == key.Key)
  1075. {
  1076. PDFViewer.SetToolParam(propertyPanel.annot);
  1077. }
  1078. }
  1079. break;
  1080. case AnnotArgsType.AnnotSquiggly:
  1081. if (e[argsType] is Color)
  1082. {
  1083. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1084. }
  1085. if (e[argsType] is double)
  1086. {
  1087. SquigglyOpacity = (double)e[argsType];
  1088. }
  1089. //创建注释后,修改注释属性,可用于下次创建的注释
  1090. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1091. {
  1092. if (StrAnnotToolChecked == key.Key)
  1093. {
  1094. PDFViewer.SetToolParam(propertyPanel.annot);
  1095. }
  1096. }
  1097. break;
  1098. case AnnotArgsType.AnnotStrikeout:
  1099. if (e[argsType] is Color)
  1100. {
  1101. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1102. }
  1103. if (e[argsType] is double)
  1104. {
  1105. StrikeoutOpacity = (double)e[argsType];
  1106. }
  1107. //创建注释后,修改注释属性,可用于下次创建的注释
  1108. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1109. {
  1110. if (StrAnnotToolChecked == key.Key)
  1111. {
  1112. PDFViewer.SetToolParam(propertyPanel.annot);
  1113. }
  1114. }
  1115. break;
  1116. case AnnotArgsType.AnnotFreehand:
  1117. if (e[argsType] is FreehandAnnotArgs)
  1118. {
  1119. var annot = e[argsType] as FreehandAnnotArgs;
  1120. if (annot != null)
  1121. {
  1122. if (propertyPanel != null)
  1123. {
  1124. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1125. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1126. propertyPanel.AnnotEvent = AnnotEvent;
  1127. var AnnotEvents = new List<AnnotAttribEvent>();
  1128. AnnotEvents.Add(AnnotEvent);
  1129. propertyPanel.AnnotEvents = AnnotEvents;
  1130. propertyPanel.annot = annot;
  1131. //手绘注释工具按钮的属性
  1132. // FreehandPath.Opacity = annot.Transparency;
  1133. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1134. }
  1135. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1136. {
  1137. if (StrAnnotToolChecked == key.Key)
  1138. {
  1139. PDFViewer.SetToolParam(propertyPanel.annot);
  1140. }
  1141. }
  1142. }
  1143. }
  1144. break;
  1145. case AnnotArgsType.AnnotErase:
  1146. if (e[argsType] is ToggleButton)
  1147. {
  1148. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1149. if (clickBtn.IsChecked == true)
  1150. {
  1151. if (clickBtn.Tag.ToString() == "PenBtn")
  1152. {
  1153. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1154. btn.Tag = "Freehand"; btn.IsChecked = true;
  1155. BtnMyTools_Click(btn);
  1156. break;
  1157. }
  1158. CreateEraseArgs();
  1159. }
  1160. }
  1161. break;
  1162. case AnnotArgsType.AnnotSquare:
  1163. case AnnotArgsType.AnnotCircle:
  1164. case AnnotArgsType.AnnotLine:
  1165. case AnnotArgsType.AnnotFreeText:
  1166. //创建注释后,修改注释属性,可用于下次创建的注释
  1167. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1168. {
  1169. if (StrAnnotToolChecked == key.Key)
  1170. {
  1171. PDFViewer.SetToolParam(propertyPanel.annot);
  1172. }
  1173. }
  1174. break;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. private void CreateEraseArgs()
  1180. {
  1181. EraseArgs eraseArgs = new EraseArgs();
  1182. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1183. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1184. eraseArgs.Thickness = 10;
  1185. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1186. if (annotProperty != null)
  1187. {
  1188. eraseArgs.Thickness = annotProperty.Thickness;
  1189. }
  1190. PDFViewer.ClearSelectAnnots(false);
  1191. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1192. PDFViewer.SetToolParam(eraseArgs);
  1193. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1194. if (eraseArgs != null)
  1195. eraseArgsList.Add(eraseArgs);
  1196. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1197. }
  1198. #endregion BindingEvent事件
  1199. }
  1200. }