AnnotToolContentViewModel.Command.cs 62 KB

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