AnnotToolContentViewModel.Command.cs 58 KB

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