AnnotToolContentViewModel.Command.cs 63 KB

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