AnnotToolContentViewModel.Command.cs 73 KB

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