AnnotToolContentViewModel.Command.cs 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.PDFDocument.Action;
  5. using ComPDFKit.PDFPage;
  6. using ComPDFKitViewer;
  7. using ComPDFKitViewer.AnnotEvent;
  8. using ComPDFKitViewer.PdfViewer;
  9. using ImTools;
  10. using PDF_Master.CustomControl;
  11. using PDF_Master.EventAggregators;
  12. using PDF_Master.Helper;
  13. using PDF_Master.Model.AnnotPanel;
  14. using PDF_Master.Model.BOTA;
  15. using PDF_Master.Model.FillAndSign;
  16. using PDF_Master.Properties;
  17. using PDF_Master.ViewModels.BOTA;
  18. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  19. using PDF_Master.ViewModels.Tools.AnnotManager;
  20. using PDF_Master.Views.BOTA;
  21. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  22. using PDFSettings;
  23. using Prism.Mvvm;
  24. using Prism.Regions;
  25. using System;
  26. using System.Collections.Generic;
  27. using System.Diagnostics;
  28. using System.Linq;
  29. using System.Windows;
  30. using System.Windows.Controls;
  31. using System.Windows.Controls.Primitives;
  32. using System.Windows.Input;
  33. using System.Windows.Markup;
  34. using System.Windows.Media;
  35. namespace PDF_Master.ViewModels.Tools
  36. {
  37. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  38. {
  39. #region 事件绑定和解绑
  40. private void BindingEvent()
  41. {
  42. //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
  43. //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
  44. PropertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  45. PropertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  46. PropertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  47. PropertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  48. //快捷键
  49. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  50. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  51. }
  52. private void UnBindingEvent()
  53. {
  54. PropertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  55. PropertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  56. //快捷盘解绑
  57. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  58. }
  59. private void BindingPDFViewerHandler()
  60. {
  61. //来自PDFViewer的响应事件
  62. if (PDFViewer != null)
  63. {
  64. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  65. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  66. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  67. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  68. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  69. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  70. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  71. PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
  72. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  73. PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
  74. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  75. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  76. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  77. PDFViewer.PreviewMouseLeftButtonDown += PDFViewer_PreviewMouseLeftButtonDown;
  78. CommandManager.AddPreviewExecutedHandler(PDFViewer, PreviewExcutePDFViewer);
  79. }
  80. }
  81. //判断
  82. private void PreviewExcutePDFViewer(object sender, ExecutedRoutedEventArgs e)
  83. {
  84. if (e.Command == ApplicationCommands.Paste)
  85. {
  86. IsPasteShape = true;
  87. ShapeNames.Clear();
  88. var items = PDFViewer.GetCopyAnnotData();
  89. foreach (var item in items)
  90. {
  91. bool IsShape = false;
  92. if (item is FreehandAnnotArgs)
  93. {
  94. foreach (var point in viewContentViewModel.FillAndSign)
  95. {
  96. if ((item as FreehandAnnotArgs).PageIndex == point.PageIndex && (item as FreehandAnnotArgs).AnnotIndex == point.AnnotIndex)
  97. {
  98. ShapeNames.Add(point.Shape);
  99. IsShape = true;
  100. continue;
  101. }
  102. }
  103. if (!IsShape)
  104. {
  105. ShapeNames.Add("Annot");
  106. }
  107. }
  108. else
  109. {
  110. ShapeNames.Add("Annot");
  111. }
  112. }
  113. }
  114. if (e.Command == ApplicationCommands.Copy)
  115. {
  116. }
  117. }
  118. private void UnBindingPDFViewerHandler()
  119. {
  120. if (PDFViewer != null)
  121. {
  122. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  123. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  124. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  125. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  126. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  127. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  128. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  129. }
  130. }
  131. #endregion 事件绑定和解绑
  132. #region 与触发事件调用相关的函数
  133. public StickyAnnotArgs GetCurrentAnnot { get; set; }
  134. //鼠标左键双击注释
  135. private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  136. {
  137. if (e.ClickCount == 1)
  138. {
  139. //不禁止取消选中注释
  140. //PDFViewer.DisableClearSelectAnnot(false);
  141. //if (viewContentViewModel.mainViewModel.IsBookMode)
  142. //{
  143. // PDFViewer.SetMouseMode(MouseModes.PanTool);
  144. // var annotArgs = new SelectToolArgs();
  145. // PDFViewer.SetToolParam(annotArgs);
  146. //}
  147. //PropertyPanel.IsSharpAnnotSelected = true;
  148. //PropertyPanel.IsFreeHandSelected = true;
  149. //PDFViewer.ClearSelectAnnots();
  150. if (StrAnnotToolChecked == "Stamp")
  151. {
  152. GetStamp();
  153. //PDFViewer.SetMouseMode(MouseModes.None);
  154. }
  155. //BOTA所有列表都需要响应 单击阅读页取消多选
  156. if (viewContentViewModel.OpenBOTA == true)
  157. {
  158. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  159. }
  160. //AnnotHandlerEventArgs annotArgs = CurrentSelectedAnnot;
  161. //if (annotArgs != null)
  162. //{
  163. // var type = annotArgs.EventType;
  164. // if (type == AnnotArgsType.AnnotSticky)
  165. // {
  166. // customStickyPopup.GetCurrentAnnot = GetCurrentAnnot;
  167. // customStickyPopup.GetPDFViewer = PDFViewer;
  168. // //多个文档时候,未知原因弹窗对象没有更改,导致PDFViewer以及GetCurrentAnnot,没有及时刷新
  169. // PDFViewer.SetStickyNotePop(customStickyPopup);
  170. // (annotArgs as StickyAnnotArgs).PopupEditWnd();
  171. // }
  172. //}
  173. }
  174. #region 0515调整的双击逻辑
  175. //if (e.ClickCount == 2)
  176. //{
  177. // if (CurrentSelectedAnnot != null)
  178. // {
  179. // var type = CurrentSelectedAnnot.EventType;
  180. // if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText && type != AnnotArgsType.AnnotLink
  181. // /*&&
  182. // type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline
  183. // && type != AnnotArgsType.AnnotStrikeout*/)
  184. // {
  185. // int dpi = DpiHelpers.Dpi;
  186. // var rect = CurrentSelectedAnnot.ClientRect;
  187. // rect = new Rect(
  188. // rect.Left * PDFViewer.ZoomFactor,
  189. // rect.Top * PDFViewer.ZoomFactor,
  190. // rect.Width * PDFViewer.ZoomFactor,
  191. // rect.Height * PDFViewer.ZoomFactor);
  192. // if (PDFViewer.Parent is ContentControl ui)
  193. // {
  194. // //var ui = PDFViewer.Parent as ContentControl;
  195. // if (ui != null)
  196. // {
  197. // var point = e.GetPosition(ui);
  198. // int pageIndex = 0;
  199. // Point pagePoint = new Point(0, 0);
  200. // PDFViewer.ConvertViewPointToPage(point, out pageIndex, out pagePoint);
  201. // if (pagePoint.X >= rect.Left && pagePoint.X <= rect.Right && pagePoint.Y >= rect.Top && pagePoint.Y <= rect.Bottom)
  202. // PopAnnotNoteText(CurrentSelectedAnnot);
  203. // }
  204. // }
  205. // }
  206. // if (type == AnnotArgsType.AnnotSticky)
  207. // {
  208. // customStickyPopup.GetCurrentAnnot = GetCurrentAnnot;
  209. // customStickyPopup.GetPDFViewer = PDFViewer;
  210. // //多个文档时候,未知原因弹窗对象没有更改,导致PDFViewer以及GetCurrentAnnot,没有及时刷新
  211. // PDFViewer.SetStickyNotePop(customStickyPopup);
  212. // (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
  213. // }
  214. // }
  215. //}
  216. #endregion 0515调整的双击逻辑
  217. }
  218. //超链接跳转
  219. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  220. {
  221. if (action == null)
  222. {
  223. return;
  224. }
  225. switch (action.ActionType)
  226. {
  227. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  228. if (PDFViewer != null)
  229. {
  230. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  231. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  232. if (dest != null)
  233. {
  234. CPDFPage docPage = PDFViewer.Document.PageAtIndex(dest.PageIndex, false);
  235. if (docPage != null)
  236. {
  237. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(dest.Position_X, docPage.PageSize.Height - dest.Position_Y));
  238. }
  239. else
  240. {
  241. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(dest.Position_X, dest.Position_Y));
  242. }
  243. }
  244. }
  245. break;
  246. case C_ACTION_TYPE.ACTION_TYPE_URI:
  247. {
  248. CPDFUriAction uriAction = action as CPDFUriAction;
  249. string uri = uriAction.GetUri();
  250. try
  251. {
  252. if (!string.IsNullOrEmpty(uri))
  253. {
  254. Process.Start(uri);
  255. }
  256. }
  257. catch (Exception ex)
  258. {
  259. }
  260. }
  261. break;
  262. }
  263. }
  264. private void GetSelectedAnnots(AnnotAttribEvent e, bool isActive = false)
  265. {
  266. var annot = e.AnnotItemsList[0];
  267. switch (annot.EventType)
  268. {
  269. case AnnotArgsType.AnnotHighlight:
  270. GetHighLight(e.AnnotItemsList);
  271. break;
  272. case AnnotArgsType.AnnotUnderline:
  273. GetUnderLine(e.AnnotItemsList);
  274. break;
  275. case AnnotArgsType.AnnotStrikeout:
  276. GetStrikeout(e.AnnotItemsList);
  277. break;
  278. case AnnotArgsType.AnnotSquiggly:
  279. GetSquiggly(e.AnnotItemsList);
  280. break;
  281. case AnnotArgsType.AnnotFreehand:
  282. GetFreehand(e.AnnotItemsList);
  283. break;
  284. case AnnotArgsType.AnnotFreeText:
  285. GetFreetext(e.AnnotItemsList);
  286. break;
  287. case AnnotArgsType.AnnotSquare:
  288. GetRect(e.AnnotItemsList);
  289. break;
  290. case AnnotArgsType.AnnotCircle:
  291. GetCircle(e.AnnotItemsList);
  292. break;
  293. case AnnotArgsType.AnnotLine:
  294. bool isLine = true;
  295. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  296. {
  297. 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)
  298. {
  299. isLine = false;
  300. }
  301. }
  302. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  303. {
  304. 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)
  305. {
  306. isLine = false;
  307. }
  308. }
  309. if (isLine)
  310. GetArrowLine("Line", e.AnnotItemsList);
  311. else
  312. GetArrowLine("Arrow", e.AnnotItemsList);
  313. break;
  314. case AnnotArgsType.AnnotLink:
  315. //viewContentViewModel.IsCreateLink = false;
  316. //e.IsAnnotCreateReset= true;
  317. if (StrAnnotToolChecked == "Link")
  318. {
  319. PropertyPanel.IsAddLink = false;
  320. }
  321. GetLink(e.AnnotItemsList, e);
  322. break;
  323. case AnnotArgsType.AnnotSticky:
  324. GetStickyNote(e.AnnotItemsList);
  325. GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  326. customStickyPopup.GetCurrentAnnot = GetCurrentAnnot;
  327. customStickyPopup.GetPDFViewer = PDFViewer;
  328. //多个文档时候,未知原因弹窗对象没有更改,导致PDFViewer以及GetCurrentAnnot,没有及时刷新
  329. PDFViewer.SetStickyNotePop(customStickyPopup);
  330. if (e.IsAnnotCreateReset)
  331. {
  332. PropertyPanel.annot = e.AnnotItemsList[0];
  333. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  334. PropertyPanel.AnnotEvents = null;
  335. PropertyPanel.AnnotEvent = AnnotEvent;
  336. PropertyPanel.annotlists = e.AnnotItemsList;
  337. }
  338. //0515 调整单击 便签弹窗
  339. if (e.AnnotItemsList.Count == 1 && e.IsMouseRightActive==false)
  340. {
  341. if (e.AnnotItemsList[0] is StickyAnnotArgs stickyAnnotArgs)
  342. {
  343. stickyAnnotArgs.PopupEditWnd();
  344. CloseAnnotToolTip();
  345. }
  346. }
  347. else
  348. {
  349. customStickyPopup.Close();
  350. }
  351. break;
  352. case AnnotArgsType.AnnotStamp:
  353. if (e.IsAnnotCreateReset == false)
  354. {
  355. GetStamp();
  356. }
  357. break;
  358. }
  359. }
  360. /// <summary>
  361. /// 选中注释 区分签名、图章、手绘
  362. /// </summary>
  363. /// <param name="annotlist"></param>
  364. private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
  365. {
  366. if (annotlist == null || annotlist.Count == 0)
  367. return;
  368. var annot = annotlist[0];
  369. if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
  370. return;
  371. if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
  372. return;
  373. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  374. if (signAnnot == null)
  375. {
  376. //var key = ToolExpandDict.FirstOrDefault(q => q.Value == annot.EventType);
  377. //if (!string.IsNullOrEmpty(StrAnnotToolChecked))
  378. // StrAnnotToolChecked = key.Key.ToString();
  379. //if (annot.EventType == AnnotArgsType.AnnotStamp)
  380. //{
  381. // StrAnnotToolChecked = "Stamp";
  382. //}
  383. //else
  384. //{
  385. // StrAnnotToolChecked = "";
  386. //}
  387. }
  388. else
  389. {
  390. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  391. {
  392. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  393. //GetSignature();
  394. //StrAnnotToolChecked = "Signature";
  395. }
  396. }
  397. }
  398. private void AddAnnotSignature(AnnotHandlerEventArgs annot)
  399. {
  400. if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
  401. (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
  402. if (StrAnnotToolChecked == "Signature")
  403. {
  404. if (viewContentViewModel.AnnotSignatures == null)
  405. viewContentViewModel.AnnotSignatures = new List<Tuple<int, int>>();
  406. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  407. if (signAnnot == null)
  408. {
  409. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
  410. }
  411. }
  412. }
  413. #endregion 与触发事件调用相关的函数
  414. #region PDFViewer事件
  415. private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
  416. private bool isShowPropertyPanel = false;
  417. //选中和非选中注释
  418. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  419. {
  420. CurrentSelectedAnnot = null;
  421. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  422. {
  423. //viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  424. return;
  425. }
  426. if (e == null)
  427. {
  428. //PDFViewer.DisableClearSelectAnnot(false);
  429. //PropertyPanel.IsSharpAnnotSelected = true;
  430. //PropertyPanel.IsFreeHandSelected = true;
  431. if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  432. {
  433. //PDFViewer.ClearSelectAnnots();
  434. CleanPropertyPanel();
  435. if (PropertyPanel.IsAddLink == false)
  436. {
  437. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  438. }
  439. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  440. //HandToolIsCheckedEvent(false);
  441. return;
  442. }
  443. else
  444. {
  445. switch (StrAnnotToolChecked)
  446. {
  447. case "HighLight"://字体高亮
  448. CleanPropertyPanel();
  449. if (selectedAnnotation != null)
  450. {
  451. if (selectedAnnotation.EventType == AnnotArgsType.AnnotHighlight)
  452. {
  453. GetHighLight();
  454. }
  455. }
  456. else
  457. {
  458. GetHighLight();
  459. }
  460. break;
  461. case "UnderLine"://下划线
  462. CleanPropertyPanel();
  463. if (selectedAnnotation != null)
  464. {
  465. if (selectedAnnotation.EventType == AnnotArgsType.AnnotUnderline)
  466. {
  467. GetUnderLine();
  468. }
  469. }
  470. else
  471. {
  472. GetUnderLine();
  473. }
  474. break;
  475. case "Strikeout"://删除线
  476. CleanPropertyPanel();
  477. if (selectedAnnotation != null)
  478. {
  479. if (selectedAnnotation.EventType == AnnotArgsType.AnnotStrikeout)
  480. {
  481. GetStrikeout();
  482. }
  483. }
  484. else
  485. {
  486. GetStrikeout();
  487. }
  488. break;
  489. }
  490. if (StrAnnotToolChecked == "Rect" && PropertyPanel.IsSelectedTextAddShape == false)
  491. {
  492. AnnotHandlerEventArgs annotArgs = null;
  493. //此处不能用这个方法更新创建注释的属性 会导致死循环
  494. //选择文字 点击矩形 会导致死循环
  495. // FindAnnotTypeKey(StrAnnotToolChecked, ref annotArgs);
  496. CleanPropertyPanel();
  497. switch (PropertyPanel.SharpsAnnot)
  498. {
  499. case "Rect":
  500. annotArgs = GetRect();
  501. break;
  502. case "Circle":
  503. annotArgs = GetCircle();
  504. break;
  505. case "Arrow":
  506. annotArgs = GetArrowLine("Arrow");
  507. break;
  508. case "Line":
  509. annotArgs = GetArrowLine("Line");
  510. break;
  511. }
  512. return;
  513. }
  514. //不可以写,手绘 改透明度 会有问题
  515. //if (StrAnnotToolChecked == "Freehand")
  516. //{
  517. // GetFreehand();
  518. //}
  519. }
  520. }
  521. if (e != null)
  522. {
  523. if (e.IsMouseRightActive)
  524. {
  525. CloseAnnotToolTip();
  526. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  527. {
  528. ShowPropertyPanel(false);
  529. return;
  530. }
  531. }
  532. var annot = e.AnnotItemsList[0];
  533. if (annot != null)
  534. {
  535. if (e.AnnotItemsList.Count == 1)
  536. {
  537. viewContentViewModel.IsMultiSelected = false;
  538. //IsAnnotCreateReset:是否为创建注释的状态
  539. if (e.IsAnnotCreateReset == false)
  540. {
  541. CurrentSelectedAnnot = annot;
  542. //未选注释工具-形状注释,选中形状注释,属性面板不显示(矩形、圆、线、箭头)
  543. if (StrAnnotToolChecked != "Rect"
  544. && (annot.EventType == AnnotArgsType.AnnotSquare ||
  545. annot.EventType == AnnotArgsType.AnnotCircle ||
  546. annot.EventType == AnnotArgsType.AnnotLine))
  547. {
  548. PropertyPanel.IsSharpAnnotSelected = false;
  549. }
  550. else
  551. {
  552. PropertyPanel.IsSharpAnnotSelected = true;
  553. }
  554. if (StrAnnotToolChecked != "Freehand" && annot.EventType == AnnotArgsType.AnnotFreehand)
  555. {
  556. PropertyPanel.IsFreeHandSelected = false;
  557. }
  558. else
  559. {
  560. PropertyPanel.IsFreeHandSelected = true;
  561. }
  562. isShowPropertyPanel = viewContentViewModel.IsPropertyOpen;
  563. if (viewContentViewModel.mainViewModel.IsBookMode == false)
  564. {
  565. GetSelectedAnnots(e, true);
  566. }
  567. SelectedSignature(e.AnnotItemsList);
  568. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty
  569. && annot.EventType != AnnotArgsType.AnnotStamp && StrAnnotToolChecked != "Signature"
  570. && annot.EventType != AnnotArgsType.AnnotLink && viewContentViewModel.mainViewModel.IsBookMode == false)
  571. {
  572. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  573. if (signAnnot == null)
  574. {
  575. if (e.IsMouseRightActive)
  576. {
  577. ShowPropertyPanel(isShowPropertyPanel);
  578. }
  579. else
  580. {
  581. ShowPropertyPanel(true);
  582. }
  583. }
  584. }
  585. else if (StrAnnotToolChecked == "Signature")
  586. {
  587. GetSignature();
  588. }
  589. //注释列表同步选中
  590. SelectedBotaAnnotationList(e);
  591. }
  592. else
  593. {
  594. if (!string.IsNullOrEmpty(StrAnnotToolChecked) || PropertyPanel.IsAddLink == true)
  595. {
  596. GetSelectedAnnots(e);
  597. PDFViewer.SetToolParam(annot);
  598. }
  599. else
  600. {
  601. if (IsNoSelectMenu)
  602. {
  603. return;
  604. }
  605. CleanPropertyPanel();
  606. PDFViewer.SetMouseMode(MouseModes.PanTool);
  607. HandToolIsCheckedEvent(false);
  608. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  609. }
  610. //switch (annot.EventType)
  611. //{
  612. // case AnnotArgsType.AnnotFreeText:
  613. // annot = GetFreetext(e.AnnotItemsList);
  614. // PDFViewer.SetToolParam(annot);
  615. // break;
  616. // case AnnotArgsType.AnnotSticky:
  617. // customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  618. // customStickyPopup.GetPDFViewer = PDFViewer;
  619. // propertyPanel.annot = e.AnnotItemsList[0];
  620. // var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  621. // propertyPanel.AnnotEvents = null;
  622. // propertyPanel.AnnotEvent = AnnotEvent;
  623. // propertyPanel.annotlists = e.AnnotItemsList;
  624. // break;
  625. // case AnnotArgsType.AnnotLink:
  626. // //viewContentViewModel.IsCreateLink = false;
  627. // GetLink(e.AnnotItemsList, e);
  628. // PDFViewer.SetToolParam(annot);
  629. // break;
  630. //}
  631. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  632. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  633. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  634. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  635. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  636. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  637. //annot.EventType != AnnotArgsType.AnnotLink &&
  638. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  639. //annot.EventType != AnnotArgsType.AnnotSticky &&
  640. //)
  641. //{
  642. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  643. // {
  644. // var strLineAnnotTag = "";
  645. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  646. // {
  647. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  648. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  649. // {
  650. // strLineAnnotTag = "Line";
  651. // }
  652. // else
  653. // {
  654. // strLineAnnotTag = "Arrow";
  655. // }
  656. // }
  657. // foreach (var item in ToolExpandDict)
  658. // {
  659. // if (item.Value == e.AnnotItemsList[0].EventType)
  660. // {
  661. // annot = null;//新建注释时,回到默认值
  662. // if (string.IsNullOrEmpty(strLineAnnotTag))
  663. // {
  664. // FindAnnotTypeKey(item.Key, ref annot);
  665. // break;
  666. // }
  667. // else
  668. // {
  669. // if (strLineAnnotTag == item.Key)
  670. // {
  671. // FindAnnotTypeKey(item.Key, ref annot);
  672. // break;
  673. // }
  674. // }
  675. // }
  676. // }
  677. // PDFViewer.SetToolParam(annot);
  678. // }
  679. //}
  680. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  681. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  682. //{
  683. // ShowPropertyPanel(false);
  684. //}
  685. //else
  686. //{
  687. // ShowPropertyPanel();
  688. //}
  689. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  690. }
  691. }
  692. else
  693. {
  694. //框选注释
  695. PropertyPanel.annotlists = e.AnnotItemsList;
  696. viewContentViewModel.IsMultiSelected = true;
  697. //viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  698. #region MVP 在对多选注释做处理
  699. bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  700. #endregion MVP 在对多选注释做处理
  701. if (viewContentViewModel.mainViewModel.IsBookMode)
  702. {
  703. ShowPropertyPanel(false);
  704. }
  705. else
  706. {
  707. if (isDifferentAnnotTyle)
  708. {
  709. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  710. ShowPropertyPanel(false);
  711. }
  712. else
  713. {
  714. GetSelectedAnnots(e);
  715. ShowPropertyPanel(true);
  716. }
  717. }
  718. }
  719. }
  720. }
  721. }
  722. private void CleanPropertyPanel()
  723. {
  724. PropertyPanel.annot = null;
  725. PropertyPanel.AnnotEvents = null;
  726. PropertyPanel.AnnotEvent = null;
  727. PropertyPanel.annotlists = null;
  728. }
  729. /// <summary>
  730. /// 注释列表同步选中
  731. /// </summary>
  732. /// <param name="e"></param>
  733. private void SelectedBotaAnnotationList(AnnotAttribEvent e)
  734. {
  735. var list = e.GetPageAnnotsIndex();
  736. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  737. //if (viewContentViewModel.OpenBOTA == false || isTabItemAnnotation == false || bOTAContent.TabItemAnnotation.IsSelected == false)
  738. //{
  739. // viewContentViewModel.OpenBOTA = true;
  740. // bOTAContent.TabItemAnnotation.IsSelected = true;
  741. //}
  742. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true /*&& bOTAContent.TabItemAnnotation.IsSelected == true*/ && list != null && list.Count > 0)
  743. {
  744. if (list.Keys.Count == 0)
  745. {
  746. return;
  747. }
  748. var pageindex = new List<int>(list.Keys);
  749. List<int> annotes = new List<int>();
  750. list.TryGetValue(pageindex[0], out annotes);
  751. int annoteindex = annotes[0];
  752. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  753. if (viewModel != null)
  754. {
  755. selectedAnnotation = viewModel.AnnotationListItems.FindFirst(a => a.PageIndex == pageindex[0] && a.AnnotIndex == annoteindex);
  756. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  757. }
  758. }
  759. }
  760. //在注释工具的状态下,右键菜单
  761. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  762. {
  763. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  764. return;
  765. if ((UIElement)sender != null)
  766. {
  767. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  768. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  769. }
  770. switch (e.CommandType)
  771. {
  772. case CommandType.Context:
  773. if (e.AnnotEventArgsList.Count > 0)
  774. {
  775. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  776. {
  777. //绑定标记密文处右键菜单
  778. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  779. }
  780. else
  781. {
  782. if (e.AnnotEventArgsList.Count == 1)
  783. {
  784. var selectedAnnot = e.AnnotEventArgsList[0];
  785. PopMenuCheckedLineDash(selectedAnnot);
  786. PopMenuCheckedFontFamily(selectedAnnot);
  787. PopMenuCheckedTextAglin(selectedAnnot);
  788. switch (selectedAnnot.EventType)
  789. {
  790. case AnnotArgsType.AnnotHighlight:
  791. case AnnotArgsType.AnnotUnderline:
  792. case AnnotArgsType.AnnotStrikeout:
  793. case AnnotArgsType.AnnotSquiggly:
  794. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  795. {
  796. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  797. }
  798. else
  799. {
  800. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  801. }
  802. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  803. break;
  804. case AnnotArgsType.AnnotFreehand:
  805. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  806. break;
  807. case AnnotArgsType.AnnotFreeText:
  808. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  809. break;
  810. case AnnotArgsType.AnnotSticky:
  811. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  812. break;
  813. case AnnotArgsType.AnnotSquare:
  814. case AnnotArgsType.AnnotCircle:
  815. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  816. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  817. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  818. break;
  819. case AnnotArgsType.AnnotLine:
  820. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  821. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  822. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  823. break;
  824. case AnnotArgsType.AnnotLink:
  825. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  826. break;
  827. case AnnotArgsType.AnnotStamp:
  828. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  829. break;
  830. }
  831. }
  832. else
  833. {
  834. bool isHigh = true;//是否为高亮
  835. foreach (var item in e.AnnotEventArgsList)
  836. {
  837. if (AnnotTransfer.IsHightAnnot(item) == false)
  838. {
  839. isHigh = false;
  840. break;
  841. }
  842. }
  843. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  844. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  845. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  846. }
  847. }
  848. if (e.PopupMenu != null)
  849. {
  850. e.Handle = true;
  851. }
  852. }
  853. else
  854. {
  855. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  856. {
  857. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  858. if (e.PopupMenu != null)
  859. {
  860. e.Handle = true;
  861. }
  862. }
  863. else
  864. {
  865. e.PopupMenu = ViewerContextMenu(sender);
  866. if (e.PopupMenu != null)
  867. {
  868. e.Handle = true;
  869. }
  870. }
  871. }
  872. break;
  873. }
  874. }
  875. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  876. {
  877. if (e.Command == ApplicationCommands.Copy || e.Command == ApplicationCommands.Cut)
  878. {
  879. if (!viewContentViewModel.CheckPermissionBeforeOption())
  880. {
  881. //没有权限,或者权限解密不成功时,拦截该命令
  882. e.Handled = true;
  883. }
  884. }
  885. }
  886. /// <summary>
  887. /// 右键菜单,选中字体样式按钮状态
  888. /// </summary>
  889. /// <param name="annot"></param>
  890. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  891. {
  892. if (annot != null)
  893. {
  894. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  895. {
  896. var freeText = annot as FreeTextAnnotArgs;
  897. string fontFamily = freeText.FontFamily.ToString();
  898. if (fontFamily == "Arial")
  899. {
  900. fontFamily = "Helvetica";
  901. }
  902. if (fontFamily == "Courier New")
  903. {
  904. fontFamily = "Courier";
  905. }
  906. if (fontFamily == "Times New Roman")
  907. {
  908. fontFamily = "Times";
  909. }
  910. FreeTextAnnotPopMenu.SetIsChecked(fontFamily, true);
  911. }
  912. }
  913. }
  914. /// <summary>
  915. /// 右键菜单,选中文本内容对齐按钮状态
  916. /// </summary>
  917. /// <param name="annot"></param>
  918. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  919. {
  920. if (annot != null)
  921. {
  922. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  923. {
  924. var freeText = annot as FreeTextAnnotArgs;
  925. switch (freeText.Align)
  926. {
  927. case TextAlignment.Left:
  928. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  929. break;
  930. case TextAlignment.Center:
  931. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  932. break;
  933. case TextAlignment.Right:
  934. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  935. break;
  936. case TextAlignment.Justify:
  937. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  938. break;
  939. default:
  940. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  941. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  942. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  943. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  944. break;
  945. }
  946. }
  947. }
  948. }
  949. //右键菜单,选中虚实线按钮状态
  950. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  951. {
  952. if (annot != null)
  953. {
  954. bool isSolidLineDash = true;
  955. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  956. {
  957. var freeHand = annot as FreehandAnnotArgs;
  958. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  959. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  960. }
  961. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  962. {
  963. var square = annot as SquareAnnotArgs;
  964. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  965. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  966. }
  967. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  968. {
  969. var circle = annot as CircleAnnotArgs;
  970. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  971. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  972. }
  973. else if (annot.EventType == AnnotArgsType.AnnotLine)
  974. {
  975. var line = annot as LineAnnotArgs;
  976. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  977. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  978. }
  979. }
  980. }
  981. /// <summary>
  982. /// 内容选择工具
  983. /// </summary>
  984. /// <param name="sender"></param>
  985. /// <param name="e"></param>
  986. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  987. {
  988. SnapshotEditToolArgs snapToolArgs = new SnapshotEditToolArgs();
  989. if (PDFViewer.ToolManager.CurrentAnnotArgs is SnapshotEditToolArgs)
  990. {
  991. snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  992. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  993. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  994. SnapshotEditMenuViewModel.areaCropPageUndoManager = new AreaCropPageUndoManager(PDFViewer);
  995. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  996. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  997. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  998. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  999. {
  1000. e.PopupMenu = popMenu;
  1001. e.Handle = true;
  1002. if (popMenu != null && popMenu.Items.Count == 5)
  1003. {
  1004. //复制
  1005. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  1006. menuItem.CommandTarget = PDFViewer;
  1007. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  1008. //导出
  1009. menuItem = popMenu.Items[1] as MenuItem;
  1010. menuItem.CommandTarget = PDFViewer;
  1011. if (menuItem.Items.Count == 3)
  1012. {
  1013. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  1014. menuItem1.CommandTarget = PDFViewer;
  1015. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  1016. menuItem1 = menuItem.Items[1] as MenuItem;
  1017. menuItem1.CommandTarget = PDFViewer;
  1018. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  1019. menuItem1 = menuItem.Items[2] as MenuItem;
  1020. menuItem1.CommandTarget = PDFViewer;
  1021. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  1022. }
  1023. //裁剪
  1024. menuItem = popMenu.Items[2] as MenuItem;
  1025. menuItem.CommandTarget = PDFViewer;
  1026. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  1027. //缩放至所选区域
  1028. menuItem = popMenu.Items[3] as MenuItem;
  1029. menuItem.CommandTarget = PDFViewer;
  1030. menuItem.Visibility = Visibility.Collapsed;
  1031. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  1032. //打印
  1033. menuItem = popMenu.Items[4] as MenuItem;
  1034. menuItem.CommandTarget = PDFViewer;
  1035. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  1036. }
  1037. }
  1038. }
  1039. }
  1040. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  1041. {
  1042. switch (e.Key)
  1043. {
  1044. case "CloseSnap":
  1045. {
  1046. #region to do
  1047. //var item = PDFViewerTab.SelectedItem as TabItem;
  1048. //if (item == null)
  1049. //{
  1050. // ClearSelectedToolPanel();
  1051. // return;
  1052. //}
  1053. //Grid grid = item.Content as Grid;
  1054. //if (grid == null || grid.Children.Count == 0)
  1055. //{
  1056. // ClearSelectedToolPanel();
  1057. // return;
  1058. //}
  1059. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  1060. //if (pdfViewer == null)
  1061. //{
  1062. // ClearSelectedToolPanel();
  1063. // return;
  1064. //}
  1065. #endregion to do
  1066. switch (PDFViewer.MouseMode)
  1067. {
  1068. case MouseModes.SelectTextTool:
  1069. break;
  1070. default:
  1071. BtnSelecttoolIsChecked = false;
  1072. //BtnHandIsChecked = true;
  1073. PDFViewer.EnableZoom(true);
  1074. PDFViewer.EnableScroll(true);
  1075. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1076. HandToolIsCheckedEvent(false);
  1077. break;
  1078. }
  1079. }
  1080. break;
  1081. default:
  1082. break;
  1083. }
  1084. }
  1085. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1086. {
  1087. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1088. AnnotationContentViewModel viewModel = null;
  1089. AnnotationContent annotation = null;
  1090. //OpenBOTA关闭时也要进入
  1091. //if (viewContentViewModel.OpenBOTA == false)
  1092. //{
  1093. viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out annotation);
  1094. //}
  1095. bool isMultiple = false;
  1096. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  1097. Dictionary<int, List<int>> selectFreehandDicts = new Dictionary<int, List<int>>();
  1098. if (e != null && e.Count > 0)
  1099. {
  1100. for (int i = 0; i < e.Count; i++)
  1101. {
  1102. AnnotEditEvent editEvent = e[i];
  1103. bool isVisible = PDFViewer.CheckAnnotVisible(editEvent.PageIndex, editEvent.AnnotIndex);
  1104. var annot = editEvent.EditAnnotArgs;
  1105. switch (editEvent.EditAction)
  1106. {
  1107. case ActionType.Add:
  1108. #region 区分复制填写签名图形
  1109. if (IsPasteShape)
  1110. {
  1111. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreehand)
  1112. {
  1113. if (ShapeNames.Count != 0 && ShapeNames[i] != "Annot")
  1114. {
  1115. try
  1116. {
  1117. viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(editEvent.PageIndex, editEvent.AnnotIndex, ShapeNames[i]));
  1118. }
  1119. catch { }
  1120. }
  1121. }
  1122. }
  1123. #endregion 区分复制填写签名图形
  1124. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  1125. {
  1126. //填写与签名在此区域不选中,不添加selectAnnotDicts词典当中
  1127. }
  1128. else
  1129. {
  1130. if (PropertyPanel.IsMultiSelected)
  1131. {
  1132. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1133. {
  1134. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1135. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1136. }
  1137. else
  1138. {
  1139. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1140. }
  1141. isMultiple = true;
  1142. }
  1143. else
  1144. {
  1145. if (
  1146. annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  1147. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp
  1148. /*|| annot.EventType == AnnotArgsType.AnnotSticky ||annot.EventType == AnnotArgsType.AnnotFreeText */)
  1149. {
  1150. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1151. {
  1152. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1153. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1154. }
  1155. else
  1156. {
  1157. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1158. }
  1159. isMultiple = true;
  1160. }
  1161. //添加后不选中的注释,需要额外处理
  1162. if (annot.EventType == AnnotArgsType.AnnotFreehand || annot.EventType == AnnotArgsType.AnnotSticky || annot.EventType == AnnotArgsType.AnnotFreeText)
  1163. {
  1164. if (selectFreehandDicts.ContainsKey(editEvent.PageIndex) == false)
  1165. {
  1166. selectFreehandDicts.Add(editEvent.PageIndex, new List<int>());
  1167. selectFreehandDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1168. }
  1169. else
  1170. {
  1171. selectFreehandDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1172. }
  1173. isMultiple = true;
  1174. }
  1175. }
  1176. }
  1177. if (viewModel != null)
  1178. {
  1179. int pageindex = editEvent.PageIndex;
  1180. int annotindex = editEvent.AnnotIndex;
  1181. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1182. }
  1183. //添加书签注释,用于未保存前跟图章手绘注释的区分
  1184. if (StrAnnotToolChecked == "Signature")
  1185. {
  1186. AddAnnotSignature(editEvent.EditAnnotArgs);
  1187. }
  1188. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  1189. //{
  1190. // (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  1191. //}
  1192. break;
  1193. case ActionType.Modify:
  1194. //if (string.IsNullOrEmpty(StrAnnotToolChecked) == false)
  1195. //{
  1196. // List<AnnotHandlerEventArgs> selectedArgs = new List<AnnotHandlerEventArgs>() { annot };
  1197. // switch (annot.EventType)
  1198. // {
  1199. // case AnnotArgsType.AnnotFreeText://文本
  1200. // GetFreetext(selectedArgs);
  1201. // break;
  1202. // }
  1203. //}
  1204. if (viewModel != null)
  1205. {
  1206. int pageindex = editEvent.PageIndex;
  1207. int annotindex = editEvent.AnnotIndex;
  1208. viewModel.UpdateModifiedAnnot(pageindex, annotindex);
  1209. }
  1210. break;
  1211. case ActionType.Del:
  1212. //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1213. //if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  1214. //{
  1215. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1216. #region//填写与签名 删除缓存信息列表
  1217. //if (Shape != "None")
  1218. //{
  1219. for (int j = 0; j < viewContentViewModel.FillAndSign.Count; j++)
  1220. {
  1221. if (viewContentViewModel.FillAndSign[j].PageIndex == editEvent.PageIndex && viewContentViewModel.FillAndSign[j].AnnotIndex == editEvent.AnnotIndex)
  1222. {
  1223. viewContentViewModel.FillAndSign.Remove(viewContentViewModel.FillAndSign[j]);
  1224. }
  1225. }
  1226. for (int j = 0; j < viewContentViewModel.AnnotSignatures.Count; j++)
  1227. {
  1228. if (viewContentViewModel.AnnotSignatures[j].Item1 == editEvent.PageIndex && viewContentViewModel.AnnotSignatures[j].Item2 == editEvent.AnnotIndex)
  1229. {
  1230. viewContentViewModel.AnnotSignatures.Remove(viewContentViewModel.AnnotSignatures[j]);
  1231. }
  1232. }
  1233. //}
  1234. #endregion PDFViewer事件
  1235. if (viewModel != null)
  1236. {
  1237. int pageindex = editEvent.PageIndex;
  1238. int annotindex = editEvent.AnnotIndex;
  1239. viewModel.DeleteModifiedAnnot(pageindex, annotindex);
  1240. }
  1241. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  1242. {
  1243. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  1244. {
  1245. //填写与签名在此区域不选中,不添加selectAnnotDicts词典当中
  1246. }
  1247. else
  1248. {
  1249. ExitAnnotationTool();
  1250. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1251. }
  1252. }
  1253. else
  1254. {
  1255. switch (StrAnnotToolChecked)
  1256. {
  1257. case "Link":
  1258. PropertyPanel.IsAddLink = true;
  1259. GetLink();
  1260. events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
  1261. break;
  1262. }
  1263. }
  1264. break;
  1265. case ActionType.TextEdit:
  1266. break;
  1267. default:
  1268. break;
  1269. }
  1270. }
  1271. IsPasteShape = false;
  1272. SetMultipleAnnot(isMultiple, selectAnnotDicts, selectFreehandDicts);
  1273. //MultipleSelectionAnnot(e);
  1274. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  1275. if (IsNoSelectMenu && PropertyPanel.IsAddLink == false)
  1276. {
  1277. viewContentViewModel.ReadModeIsShowProperty = false;
  1278. IsNoSelectMenu = false;
  1279. ExitAnnotationTool();
  1280. }
  1281. if (viewContentViewModel.IsRightMenuSelectedTextAddLink == false)
  1282. {
  1283. viewContentViewModel.ReadModeIsShowProperty = false;
  1284. }
  1285. }
  1286. }
  1287. /// <summary>
  1288. /// 设置多选注释
  1289. /// </summary>
  1290. /// <param name="isMultiple"></param>
  1291. /// <param name="selectAnnotDicts">添加后选中的注释</param>
  1292. /// <param name="selectFreehandDicts">添加后不选中的注释,需要额外处理</param>
  1293. private void SetMultipleAnnot(bool isMultiple, Dictionary<int, List<int>> selectAnnotDicts, Dictionary<int, List<int>> selectFreehandDicts)
  1294. {
  1295. if (isMultiple)
  1296. {
  1297. Dictionary<int, List<int>> dict = new Dictionary<int, List<int>>();
  1298. //阅读页多选注释,只能在当前页多选,不可以跨页多选
  1299. if (selectAnnotDicts.Count >= 1)
  1300. {
  1301. PDFViewer.ClearSelectAnnots();
  1302. //if (StrAnnotToolChecked != "Signature")
  1303. //{
  1304. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1305. if (selectFreehandDicts.Count >= 1)
  1306. {
  1307. if (selectFreehandDicts.FirstOrDefault().Value.Count > 1)
  1308. {
  1309. //先把键都合并到dict中,值都是新创建的
  1310. foreach (var key in selectAnnotDicts.Keys)
  1311. {
  1312. if (!dict.ContainsKey(key))
  1313. {
  1314. dict.Add(key, new List<int>());
  1315. }
  1316. }
  1317. foreach (var key in selectFreehandDicts.Keys)
  1318. {
  1319. if (!dict.ContainsKey(key))
  1320. {
  1321. dict.Add(key, new List<int>());
  1322. }
  1323. }
  1324. //分别将值添加进去
  1325. foreach (var ele in selectAnnotDicts)
  1326. {
  1327. dict[ele.Key].AddRange(ele.Value);
  1328. }
  1329. foreach (var ele in selectFreehandDicts)
  1330. {
  1331. dict[ele.Key].AddRange(ele.Value);
  1332. }
  1333. //Dictionary<int, List<int>> items2 = selectAnnotDicts.Union(selectFreehandDicts).ToDictionary(k => k.Key, v => v.Value);
  1334. PDFViewer.ClearSelectAnnots();
  1335. PDFViewer.SelectAnnotation(dict);
  1336. }
  1337. //}
  1338. }
  1339. }
  1340. else
  1341. {
  1342. if (selectFreehandDicts.Count >= 1)
  1343. {
  1344. if (selectFreehandDicts.FirstOrDefault().Value.Count > 1)
  1345. {
  1346. PDFViewer.ClearSelectAnnots();
  1347. PDFViewer.SelectAnnotation(selectFreehandDicts);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. #region 之前版本
  1353. //if (isMultiple && selectAnnotDicts.Count >= 1)
  1354. //{
  1355. // //PDFViewer.DisableClearSelectAnnot(false);
  1356. // PDFViewer.ClearSelectAnnots();
  1357. // if (StrAnnotToolChecked != "Signature")
  1358. // {
  1359. // //PDFViewer.DisableClearSelectAnnot(true);
  1360. // PDFViewer.SelectAnnotation(selectAnnotDicts);
  1361. // //禁止取消选中注释
  1362. // //PDFViewer.DisableClearSelectAnnot(false);
  1363. // }
  1364. //}
  1365. //if (isMultiple && selectFreehandDicts.Count >= 1)
  1366. //{
  1367. // PDFViewer.ClearSelectAnnots();
  1368. // if (selectFreehandDicts.FirstOrDefault().Value.Count >= 1)
  1369. // {
  1370. // PDFViewer.SelectAnnotation(selectFreehandDicts);
  1371. // }
  1372. //}
  1373. #endregion 之前版本
  1374. }
  1375. //复制多个注释,粘贴后,默认注释未选中状态
  1376. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  1377. {
  1378. bool isAdd = false;
  1379. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  1380. foreach (var item in e)
  1381. {
  1382. if (item.EditAction == ActionType.Add || item.EditAction == ActionType.Modify)
  1383. {
  1384. var annot = item.EditAnnotArgs;
  1385. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  1386. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand)
  1387. {
  1388. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  1389. {
  1390. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  1391. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1392. }
  1393. else
  1394. {
  1395. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1396. }
  1397. isAdd = true;
  1398. }
  1399. }
  1400. }
  1401. if (isAdd && selectAnnotDicts.Count >= 1)
  1402. {
  1403. PDFViewer.ClearSelectAnnots();
  1404. if (StrAnnotToolChecked != "Signature")
  1405. {
  1406. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1407. }
  1408. }
  1409. }
  1410. private bool isDown = true;
  1411. //阅读页悬浮相应
  1412. /// <summary>
  1413. /// 阅读页鼠标悬浮在注释上的虚线
  1414. /// </summary>
  1415. /// <param name="sender"></param>
  1416. /// <param name="e"></param>
  1417. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1418. {
  1419. if (e != null && e.DrawContext != null)
  1420. {
  1421. //if (StrAnnotToolChecked == "Freetext")
  1422. //{
  1423. // if ((e.Annot is CPDFFreeTextAnnotation annotation) == false)
  1424. // {
  1425. // isDown = false;
  1426. // Trace.WriteLine(isDown);
  1427. // return;
  1428. // }
  1429. // else
  1430. // {
  1431. // isDown=true;
  1432. // Trace.WriteLine(isDown);
  1433. // }
  1434. //}
  1435. if (StrAnnotToolChecked != "Link")
  1436. {
  1437. if (e.Annot is CPDFLinkAnnotation linkAnnotation)
  1438. {
  1439. return;
  1440. }
  1441. }
  1442. if (StrAnnotToolChecked == "Freehand" || (IsNoSelectMenu && isRightMenuAddAnnot))
  1443. {
  1444. return;
  1445. }
  1446. Rect hoverRect = new Rect(
  1447. e.PaintRect.Left - 2,
  1448. e.PaintRect.Top - 2,
  1449. e.PaintRect.Width + 4,
  1450. e.PaintRect.Height + 4);
  1451. if (e.Annot is CPDFTextAnnotation sticky)
  1452. {
  1453. hoverRect = new Rect(
  1454. e.PaintRect.Left - 2,
  1455. e.PaintRect.Top + 2,
  1456. e.PaintRect.Width + 5,
  1457. e.PaintRect.Height + 2);
  1458. }
  1459. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1460. hoverPen.DashStyle = DashStyles.Dash;
  1461. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1462. //便签,显示ToolTip内容
  1463. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  1464. {
  1465. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  1466. return;
  1467. }
  1468. }
  1469. CloseAnnotToolTip();
  1470. }
  1471. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1472. {
  1473. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1474. {
  1475. //鼠标移到注释之外,关闭ToolTip浮窗
  1476. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1477. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1478. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1479. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1480. {
  1481. CloseAnnotToolTip();
  1482. }
  1483. }
  1484. }
  1485. private Rect oldRect = new Rect(0, 0, 0, 0);
  1486. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  1487. {
  1488. //便签,显示ToolTip内容
  1489. if (PDFViewer.ToolTip == null)
  1490. {
  1491. if (string.IsNullOrEmpty(content) == false)
  1492. {
  1493. ToolTip TipChild = new ToolTip();
  1494. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  1495. TipChild.MaxWidth = 246;
  1496. TipChild.Content = content;
  1497. TipChild.Visibility = Visibility.Visible;
  1498. TipChild.IsOpen = true;
  1499. TipChild.Placement = PlacementMode.Right;
  1500. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  1501. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1502. TipChild.Placement = PlacementMode.MousePoint;
  1503. PDFViewer.ToolTip = TipChild;
  1504. oldRect = hoverRect;
  1505. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1506. PDFViewer.MouseMove += PDFViewer_MouseMove;
  1507. }
  1508. }
  1509. }
  1510. //关闭ToolTip
  1511. private void CloseAnnotToolTip()
  1512. {
  1513. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1514. {
  1515. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1516. oldTips.IsOpen = false;
  1517. oldTips.Visibility = Visibility.Collapsed;
  1518. PDFViewer.ToolTip = null;
  1519. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1520. oldRect = new Rect(0, 0, 0, 0);
  1521. }
  1522. }
  1523. #endregion PDFViewer事件
  1524. #region BindingEvent事件
  1525. //同一属性面板,不同的注释类型
  1526. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1527. {
  1528. if (e != null && sender is SharpsAnnotPropertyViewModel sharpsAnnot)
  1529. {
  1530. AnnotHandlerEventArgs annotArgs = null;
  1531. //PropertyPanel.SaveLastAnnot();
  1532. List<AnnotHandlerEventArgs> annots = new List<AnnotHandlerEventArgs>();
  1533. foreach (AnnotArgsType argsType in e.Keys)
  1534. {
  1535. if (PropertyPanel.annot != null)
  1536. {
  1537. if (PropertyPanel.annot.EventType != argsType)
  1538. {
  1539. PDFViewer.DisableClearSelectAnnot(false);
  1540. PDFViewer.ClearSelectAnnots();
  1541. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1542. CurrentSelectedAnnot = null;
  1543. }
  1544. }
  1545. switch (argsType)
  1546. {
  1547. case AnnotArgsType.AnnotSquare:
  1548. #region TO DO
  1549. //选择一个形状注释A,在选择B(非多选),修改属性成功,以下操作的操作可以解决,
  1550. //可能会出现选择注释A,鼠标直接点击属性面板,注释A取消选中,但还可以对注释A更改属性的BUG
  1551. if (CurrentSelectedAnnot != null)
  1552. {
  1553. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotSquare)
  1554. {
  1555. //CurrentSelectedAnnot.PageIndex = -1;
  1556. //CurrentSelectedAnnot.AnnotIndex = -1;
  1557. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1558. annots.Add(CurrentSelectedAnnot);
  1559. }
  1560. }
  1561. if (annots.Count > 0)
  1562. {
  1563. annotArgs = GetRect(annots);
  1564. }
  1565. else
  1566. {
  1567. annotArgs = GetRect();
  1568. }
  1569. #endregion TO DO
  1570. //annotArgs = GetRect();
  1571. break;
  1572. case AnnotArgsType.AnnotCircle:
  1573. #region TO DO
  1574. if (CurrentSelectedAnnot != null)
  1575. {
  1576. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotCircle)
  1577. {
  1578. //CurrentSelectedAnnot.PageIndex = -1;
  1579. //CurrentSelectedAnnot.AnnotIndex = -1;
  1580. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1581. annots.Add(CurrentSelectedAnnot);
  1582. }
  1583. }
  1584. if (annots.Count > 0)
  1585. {
  1586. annotArgs = GetCircle(annots);
  1587. }
  1588. else
  1589. {
  1590. annotArgs = GetCircle();
  1591. }
  1592. #endregion TO DO
  1593. //annotArgs = GetCircle();
  1594. break;
  1595. case AnnotArgsType.AnnotLine:
  1596. var LineTag = e[argsType] as string;
  1597. #region TO DO
  1598. if (CurrentSelectedAnnot != null)
  1599. {
  1600. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotLine)
  1601. {
  1602. //CurrentSelectedAnnot.PageIndex = -1;
  1603. //CurrentSelectedAnnot.AnnotIndex = -1;
  1604. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1605. if (CurrentSelectedAnnot is LineAnnotArgs lineAnnotArgs)
  1606. {
  1607. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  1608. {
  1609. if (LineTag == "Arrow")
  1610. {
  1611. annots.Add(CurrentSelectedAnnot);
  1612. }
  1613. }
  1614. else
  1615. {
  1616. if (LineTag == "Line")
  1617. {
  1618. annots.Add(CurrentSelectedAnnot);
  1619. }
  1620. }
  1621. }
  1622. }
  1623. }
  1624. if (annots.Count > 0)
  1625. {
  1626. annotArgs = GetArrowLine(LineTag, annots);
  1627. }
  1628. else
  1629. {
  1630. annotArgs = GetArrowLine(LineTag);
  1631. }
  1632. #endregion TO DO
  1633. //annotArgs = GetArrowLine(LineTag);
  1634. break;
  1635. }
  1636. ShowPropertyPanel();
  1637. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  1638. {
  1639. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  1640. return;
  1641. }
  1642. if (annotArgs != null)
  1643. {
  1644. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1645. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1646. PDFViewer.SetToolParam(annotArgs);
  1647. }
  1648. }
  1649. }
  1650. }
  1651. //来自属性面板的事件,更改颜色等属性而触发
  1652. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1653. {
  1654. if (e != null)
  1655. {
  1656. PropertyPanel.annot.Author = Settings.Default.AppProperties.Description.Author;
  1657. foreach (AnnotArgsType argsType in e.Keys)
  1658. {
  1659. var key = ToolExpandDict.FirstOrDefault(q => q.Value == argsType);
  1660. switch (argsType)
  1661. {
  1662. case AnnotArgsType.AnnotHighlight:
  1663. if (e[argsType] is Color)
  1664. {
  1665. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  1666. }
  1667. if (e[argsType] is double)
  1668. {
  1669. HighLightOpacity = (double)e[argsType];
  1670. }
  1671. //创建注释后,修改注释属性,可用于下次创建的注释
  1672. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1673. {
  1674. if (StrAnnotToolChecked == key.Key)
  1675. {
  1676. PDFViewer.SetToolParam(PropertyPanel.annot);
  1677. }
  1678. }
  1679. break;
  1680. case AnnotArgsType.AnnotUnderline:
  1681. if (e[argsType] is Color)
  1682. {
  1683. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1684. }
  1685. if (e[argsType] is double)
  1686. {
  1687. UnderLineOpacity = (double)e[argsType];
  1688. }
  1689. //创建注释后,修改注释属性,可用于下次创建的注释
  1690. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1691. {
  1692. if (StrAnnotToolChecked == key.Key)
  1693. {
  1694. PDFViewer.SetToolParam(PropertyPanel.annot);
  1695. }
  1696. }
  1697. break;
  1698. case AnnotArgsType.AnnotSquiggly:
  1699. if (e[argsType] is Color)
  1700. {
  1701. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1702. }
  1703. if (e[argsType] is double)
  1704. {
  1705. SquigglyOpacity = (double)e[argsType];
  1706. }
  1707. //创建注释后,修改注释属性,可用于下次创建的注释
  1708. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1709. {
  1710. if (StrAnnotToolChecked == key.Key)
  1711. {
  1712. PDFViewer.SetToolParam(PropertyPanel.annot);
  1713. }
  1714. }
  1715. break;
  1716. case AnnotArgsType.AnnotStrikeout:
  1717. if (e[argsType] is Color)
  1718. {
  1719. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1720. }
  1721. if (e[argsType] is double)
  1722. {
  1723. StrikeoutOpacity = (double)e[argsType];
  1724. }
  1725. //创建注释后,修改注释属性,可用于下次创建的注释
  1726. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1727. {
  1728. if (StrAnnotToolChecked == key.Key)
  1729. {
  1730. PDFViewer.SetToolParam(PropertyPanel.annot);
  1731. }
  1732. }
  1733. break;
  1734. case AnnotArgsType.AnnotFreehand:
  1735. if (e[argsType] is FreehandAnnotArgs)
  1736. {
  1737. var annot = e[argsType] as FreehandAnnotArgs;
  1738. if (annot != null)
  1739. {
  1740. if (PropertyPanel != null)
  1741. {
  1742. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1743. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1744. PropertyPanel.AnnotEvent = AnnotEvent;
  1745. var AnnotEvents = new List<AnnotAttribEvent>();
  1746. AnnotEvents.Add(AnnotEvent);
  1747. PropertyPanel.AnnotEvents = AnnotEvents;
  1748. PropertyPanel.annot = annot;
  1749. //手绘注释工具按钮的属性
  1750. // FreehandPath.Opacity = annot.Transparency;
  1751. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1752. }
  1753. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1754. {
  1755. if (StrAnnotToolChecked == key.Key)
  1756. {
  1757. PDFViewer.SetToolParam(PropertyPanel.annot);
  1758. }
  1759. }
  1760. }
  1761. }
  1762. break;
  1763. case AnnotArgsType.AnnotErase:
  1764. if (e[argsType] is ToggleButton)
  1765. {
  1766. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1767. if (clickBtn.IsChecked == true)
  1768. {
  1769. if (clickBtn.Tag.ToString() != "PenBtn")
  1770. {
  1771. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1772. btn.Tag = "Freehand";
  1773. btn.IsChecked = true;
  1774. BtnMyTools_Click(btn);
  1775. break;
  1776. }
  1777. else
  1778. {
  1779. CreateEraseArgs();
  1780. }
  1781. }
  1782. }
  1783. break;
  1784. case AnnotArgsType.AnnotSquare:
  1785. case AnnotArgsType.AnnotCircle:
  1786. case AnnotArgsType.AnnotLine:
  1787. //创建注释后,修改注释属性,可用于下次创建的注释
  1788. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1789. {
  1790. if (StrAnnotToolChecked == "Rect")
  1791. {
  1792. if (PropertyPanel.SharpsAnnot == key.Key || (PropertyPanel.SharpsAnnot != key.Key && key.Key == "Arrow"))
  1793. {
  1794. PDFViewer.SetToolParam(PropertyPanel.annot);
  1795. }
  1796. PropertyPanel.SaveLastAnnot();
  1797. }
  1798. }
  1799. break;
  1800. case AnnotArgsType.AnnotFreeText:
  1801. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1802. {
  1803. if (StrAnnotToolChecked == key.Key)
  1804. {
  1805. PDFViewer.SetToolParam(PropertyPanel.annot);
  1806. }
  1807. }
  1808. break;
  1809. }
  1810. }
  1811. }
  1812. }
  1813. private void CreateEraseArgs()
  1814. {
  1815. EraseArgs eraseArgs = new EraseArgs();
  1816. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1817. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1818. eraseArgs.Thickness = 10;
  1819. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1820. if (annotProperty != null)
  1821. {
  1822. eraseArgs.Thickness = annotProperty.Thickness;
  1823. }
  1824. PDFViewer.ClearSelectAnnots(false);
  1825. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1826. PDFViewer.SetToolParam(eraseArgs);
  1827. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1828. if (eraseArgs != null)
  1829. eraseArgsList.Add(eraseArgs);
  1830. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1831. }
  1832. #endregion BindingEvent事件
  1833. }
  1834. }