AnnotToolContentViewModel.Command.cs 63 KB

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