AnnotToolContentViewModel.Command.cs 59 KB

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