AnnotToolContentViewModel.Command.cs 73 KB

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