FillAndSignContentViewModel.cs 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Office.Model;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using PDF_Office.ViewModels.Tools;
  15. using ComPDFKitViewer;
  16. using PDF_Office.Helper;
  17. using PDF_Office.Properties;
  18. using PDFSettings;
  19. using System.Windows.Media;
  20. using ComPDFKit.PDFDocument.Action;
  21. using ComPDFKit.PDFDocument;
  22. using System.Diagnostics;
  23. using ComPDFKit.PDFAnnotation;
  24. using PDF_Office.ViewModels.BOTA;
  25. using PDF_Office.Views.BOTA;
  26. using System.Windows.Forms;
  27. using Control = System.Windows.Controls.Control;
  28. using Microsoft.Office.Interop.Word;
  29. using Point = System.Windows.Point;
  30. using System.Windows.Ink;
  31. using PDF_Office.EventAggregators;
  32. using System.Management.Instrumentation;
  33. using Prism.Events;
  34. using System.Windows.Input;
  35. using ContextMenu = System.Windows.Controls.ContextMenu;
  36. using MenuItem = System.Windows.Controls.MenuItem;
  37. using System.Drawing;
  38. using Color = System.Windows.Media.Color;
  39. using Brush = System.Windows.Media.Brush;
  40. using FontFamily = System.Windows.Media.FontFamily;
  41. using ToolTip = System.Windows.Controls.ToolTip;
  42. using ContentControl = System.Windows.Controls.ContentControl;
  43. using MouseEventArgs = System.Windows.Input.MouseEventArgs;
  44. using Pen = System.Windows.Media.Pen;
  45. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  46. using RadioButton = System.Windows.Controls.RadioButton;
  47. using Style = System.Windows.Style;
  48. using PDF_Office.CustomControl;
  49. using System.Windows.Controls.Primitives;
  50. using Window = System.Windows.Window;
  51. using Task = System.Threading.Tasks.Task;
  52. using Size = System.Windows.Size;
  53. using System.Windows.Markup;
  54. using Prism.Services.Dialogs;
  55. namespace PDF_Office.ViewModels.FillAndSign
  56. {
  57. public class FillAndSignContentViewModel : BindableBase, INavigationAware
  58. {
  59. #region
  60. private CPDFViewer PDFViewer;
  61. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  62. private ViewContentViewModel viewContentViewModel;
  63. private bool isRightMenuAddAnnot = false;
  64. private IEventAggregator events;
  65. public List<List<Point>> ShapePoints = new List<List<Point>>();
  66. private string Shape = "HookShape";
  67. private PopMenu FreeHandAnnotPopMenu;
  68. private PopMenu FreeTextAnnotPopMenu;
  69. private PopMenu MultiAnnotPopMenu;
  70. public bool isFirst=true;
  71. private IRegionManager regions { get; set; }
  72. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  73. public static bool IsEdit = false;
  74. public static bool IsSignPoint = false;
  75. public Brush SelectColor = new SolidColorBrush(Colors.GreenYellow);
  76. public double FillOpacity = 1;
  77. public double LineWidth = 1;
  78. public double LineWidthMultiple = 1;
  79. private bool _HookShapeIsCheck = true;
  80. public bool HookShapeIsCheck
  81. {
  82. get { return _HookShapeIsCheck; }
  83. set { SetProperty(ref _HookShapeIsCheck, value); }
  84. }
  85. #endregion
  86. public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
  87. public DelegateCommand<object> FreeTextFontFamily_MenuCommand { get; set; }
  88. public DelegateCommand<object> AnnotColorPalette_MenuCommand { get; set; }
  89. public DelegateCommand<object> FreeTextAglin_MenuCommand { get; set; }
  90. #region Command
  91. public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }
  92. /// <summary>
  93. /// 按钮名称和属性面板映射字典
  94. /// </summary>
  95. public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
  96. private IDialogService dialogs;
  97. #endregion
  98. string Unicode = "";
  99. public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events,IDialogService dialogService)
  100. {
  101. dialogs = dialogService;
  102. regions = regionManager;
  103. this.events = events;
  104. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  105. CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
  106. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  107. InitDictionary();
  108. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  109. AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
  110. FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
  111. FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
  112. InitSelectFreeHandAnnotMenu();
  113. InitSelectFreeTextAnnotMenu();
  114. InitSelectMultiAnnotMenu();
  115. SubscribeEvent();
  116. }
  117. #region 事件聚合器(来自AnnotToolContentViewModel)
  118. private void SubscribeEvent()
  119. {
  120. events.GetEvent<FillAndSignEvent>().Subscribe(FromFillAndSign, e => e.AppUnicode == Unicode);
  121. }
  122. private void FromFillAndSign(FillAndSigntEventArgs obj)
  123. {
  124. if(obj != null)
  125. {
  126. if(string.IsNullOrEmpty(obj.Unicode) == false)
  127. {
  128. if(obj.Unicode == "Clear")
  129. {
  130. viewContentViewModel.FillAndSign.Clear();
  131. }
  132. else
  133. {
  134. if(obj.Annots != null && obj.Annots.Count > 0)
  135. {
  136. if (obj.Annots[0].EventType == AnnotArgsType.AnnotFreehand)
  137. {
  138. GetFreehand(obj.Annots);
  139. }
  140. else if(obj.Annots[0].EventType == AnnotArgsType.AnnotFreeText)
  141. {
  142. GetFreetext(obj.Annots);
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. #endregion 事件聚合器
  150. private void InitFillAndSignProperty()
  151. {
  152. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
  153. SelectColor = new SolidColorBrush(FreehandDefault.BorderColor != Color.FromArgb(0, 0, 0, 0) ? FreehandDefault.BorderColor : Colors.GreenYellow);
  154. FillOpacity = FreehandDefault.Opacity > 0 ? FreehandDefault.Opacity : 1;
  155. LineWidth = FreehandDefault.Thickness > 0 ? FreehandDefault.Thickness : 1;
  156. }
  157. private System.Windows.Controls.Primitives.Popup popup = null;
  158. private async void AnnotColorPalette_Menu(object obj)
  159. {
  160. if (obj as CusMenuItem != null)
  161. {
  162. var menu = obj as CusMenuItem;
  163. var annot = menu.Parameter as AnnotHandlerEventArgs;
  164. if (annot != null)
  165. {
  166. var item = new ColorDropBoxPop();
  167. item.DataContext = menu;
  168. item.ColorSelected -= AnnotMenu_ColorSelected;
  169. item.ColorSelected += AnnotMenu_ColorSelected;
  170. if (popup == null)
  171. popup = new System.Windows.Controls.Primitives.Popup();
  172. ContentControl window = null;
  173. if (PDFViewer.Parent as ContentControl != null)
  174. window = PDFViewer.Parent as ContentControl;
  175. else
  176. window = App.Current.MainWindow;
  177. popup.Child = item;
  178. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  179. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  180. popup.PlacementTarget = window;
  181. popup.IsOpen = true;
  182. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  183. if (parentWnd != null)
  184. {
  185. parentWnd.MouseDown -= parentWnd_MouseDown;
  186. parentWnd.MouseDown += parentWnd_MouseDown;
  187. }
  188. while (popup.IsOpen)
  189. await Task.Delay(20);
  190. parentWnd.MouseDown -= parentWnd_MouseDown;
  191. popup = null;
  192. }
  193. }
  194. }
  195. private void AnnotMenu_ColorSelected(object sender, Color e)
  196. {
  197. if (sender != null)
  198. {
  199. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  200. if (menu == null) return;
  201. var annot = menu.Parameter as AnnotHandlerEventArgs;
  202. if (annot != null)
  203. {
  204. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  205. {
  206. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  207. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  208. AnnotEvent?.UpdateAnnot();
  209. }
  210. else if (annot is FreeTextAnnotArgs)
  211. {
  212. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  213. if (menu.tag.ToString() == "FontColor")
  214. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  215. else
  216. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  217. AnnotEvent?.UpdateAnnot();
  218. }
  219. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  220. {
  221. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  222. if (menu.tag.ToString() == "FillColor")
  223. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  224. else
  225. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  226. AnnotEvent?.UpdateAnnot();
  227. }
  228. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  229. {
  230. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  231. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  232. AnnotEvent?.UpdateAnnot();
  233. }
  234. }
  235. }
  236. }
  237. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  238. {
  239. var ui = Mouse.DirectlyOver as FrameworkElement;
  240. if (ui != null)
  241. {
  242. if (popup != null)
  243. {
  244. popup.IsOpen = false;
  245. }
  246. }
  247. }
  248. private void FreeTextFontFamily_Menu(object obj)
  249. {
  250. if (obj as CusMenuItem != null)
  251. {
  252. var menu = obj as CusMenuItem;
  253. var annot = menu.Parameter as AnnotHandlerEventArgs;
  254. if (annot != null)
  255. {
  256. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  257. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  258. AnnotEvent?.UpdateAnnot();
  259. }
  260. }
  261. }
  262. private void FreeTextAglin_Menu(object obj)
  263. {
  264. if (obj as CusMenuItem != null)
  265. {
  266. var menu = obj as CusMenuItem;
  267. var annot = menu.Parameter as AnnotHandlerEventArgs;
  268. var tag = menu.control.Tag;
  269. if (annot != null && tag != null)
  270. {
  271. var strTag = tag.ToString();
  272. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  273. if (strTag == "Left")
  274. {
  275. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  276. }
  277. else if (strTag == "Center")
  278. {
  279. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  280. }
  281. else if (strTag == "Right")
  282. {
  283. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  284. }
  285. else if (strTag == "Justify")
  286. {
  287. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  288. }
  289. AnnotEvent?.UpdateAnnot();
  290. }
  291. }
  292. }
  293. private void AnnotDefaultValues_Menu(object obj)
  294. {
  295. if (obj as CusMenuItem != null)
  296. {
  297. var menu = obj as CusMenuItem;
  298. var annot = menu.Parameter as AnnotHandlerEventArgs;
  299. if (annot != null)
  300. {
  301. if (annot is FreehandAnnotArgs)
  302. {
  303. var freeHand = annot as FreehandAnnotArgs;
  304. var color = freeHand.InkColor;
  305. //Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  306. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
  307. FreehandDefault.BorderColor = color;
  308. FreehandDefault.Opacity = freeHand.Transparency;
  309. FreehandDefault.Thickness = freeHand.LineWidth;
  310. FreehandDefault.SaveKey = "FillAndSign";
  311. var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
  312. if (isSolid)
  313. {
  314. FreehandDefault.DashArray = null;
  315. }
  316. else
  317. {
  318. FreehandDefault.DashArray = new List<double>();
  319. foreach (var item in freeHand.LineDash.Dashes)
  320. {
  321. FreehandDefault.DashArray.Add(item);
  322. }
  323. }
  324. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  325. }
  326. else if (annot is FreeTextAnnotArgs)
  327. {
  328. var freeText = annot as FreeTextAnnotArgs;
  329. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  330. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  331. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  332. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  333. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  334. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  335. FreeTextDefalut.TextAlign = freeText.Align;
  336. FreeTextDefalut.FontSize = freeText.FontSize;
  337. FreeTextDefalut.FontWeight = freeText.FontWeight;
  338. FreeTextDefalut.FontStyle = freeText.FontStyle;
  339. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  340. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  341. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  342. }
  343. }
  344. }
  345. }
  346. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType,string savaKey="")
  347. {
  348. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, savaKey);
  349. if (Annot == null)
  350. {
  351. Annot = new DefaultAnnotProperty();
  352. Annot.AnnotToolType = annotArgsType;
  353. }
  354. return Annot;
  355. }
  356. private void CheckedEvent(RoutedEventArgs e)
  357. {
  358. var control = e.OriginalSource as Control;
  359. IsEdit = false;
  360. //NavigateToProperty(control.Name);
  361. //不创建注释,属于注释模板
  362. bool isTemplateAnnot = false;
  363. bool isSnapshotEdit = false;
  364. AnnotHandlerEventArgs annotArgs = null;
  365. //付费锁
  366. if (!App.IsLogin)
  367. {
  368. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  369. return;
  370. }
  371. var tag = control.Name;
  372. FindAnnotTypeKey(control.Name, ref annotArgs);
  373. if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
  374. if (tag == "SnapshotEdit")
  375. {
  376. isSnapshotEdit = true;
  377. }
  378. else if (tag == "Signature" || tag == "Stamp")
  379. {
  380. isTemplateAnnot = true;
  381. }
  382. if (annotArgs != null)
  383. {
  384. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  385. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  386. PDFViewer.SetToolParam(annotArgs);
  387. isRightMenuAddAnnot = false;
  388. }
  389. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  390. if (isTemplateAnnot == false && annotArgs == null)
  391. {
  392. PDFViewer.SetMouseMode(MouseModes.PanTool);
  393. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  394. }
  395. else
  396. {
  397. if (isSnapshotEdit == true)
  398. {
  399. ShowPropertyPanel(false);
  400. isSnapshotEdit = false;
  401. }
  402. else
  403. {
  404. ShowPropertyPanel(true);
  405. }
  406. }
  407. }
  408. private void InitCheckedEvent(string e)
  409. {
  410. IsEdit = false;
  411. //NavigateToProperty(control.Name);
  412. //不创建注释,属于注释模板
  413. bool isTemplateAnnot = false;
  414. bool isSnapshotEdit = false;
  415. AnnotHandlerEventArgs annotArgs = null;
  416. var tag = e;
  417. FindAnnotTypeKey(e, ref annotArgs);
  418. if (e == "RbtnSign") { isTemplateAnnot = true; }
  419. if (tag == "SnapshotEdit")
  420. {
  421. isSnapshotEdit = true;
  422. }
  423. else if (tag == "Signature" || tag == "Stamp")
  424. {
  425. isTemplateAnnot = true;
  426. }
  427. if (annotArgs != null)
  428. {
  429. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  430. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  431. PDFViewer.SetToolParam(annotArgs);
  432. isRightMenuAddAnnot = false;
  433. }
  434. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  435. if (isTemplateAnnot == false && annotArgs == null)
  436. {
  437. PDFViewer.SetMouseMode(MouseModes.PanTool);
  438. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  439. }
  440. else
  441. {
  442. if (isSnapshotEdit == true)
  443. {
  444. ShowPropertyPanel(false);
  445. isSnapshotEdit = false;
  446. }
  447. else
  448. {
  449. ShowPropertyPanel(true);
  450. }
  451. }
  452. }
  453. //注释工具
  454. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  455. {
  456. LineWidthMultiple = 1;
  457. IsSignPoint = false;
  458. switch (tag)
  459. {
  460. case "RbtnDate":
  461. case "RbtnText"://文本
  462. annotArgs = GetFreetext();
  463. break;
  464. case "Freetext"://文本
  465. annotArgs = GetFreetext();
  466. break;
  467. case "RbtnSign"://签名
  468. annotArgs = GetSignature();
  469. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  470. break;
  471. case "RbtnTick"://勾
  472. Shape = "HookShape";
  473. ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
  474. annotArgs = GetStamp();
  475. break;
  476. case "RbtnFork"://叉
  477. Shape = "ForkShape";
  478. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } };
  479. annotArgs = GetStamp();
  480. break;
  481. case "RbtnRectangle"://矩形
  482. Shape = "RectShape";
  483. ShapePoints = new List<List<Point>> { new List<Point> { new Point(5, 5), new Point(28, 5) }, new List<Point> { new Point(28, 5), new Point(28, 27) }, new List<Point> { new Point(28, 27), new Point(5, 27) }, new List<Point> { new Point(5, 27), new Point(5, 5) } };
  484. annotArgs = GetStamp();
  485. break;
  486. case "RbtnLine"://下划线
  487. Shape = "LineShape";
  488. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
  489. annotArgs = GetStamp();
  490. break;
  491. case "RbtnPoint":
  492. IsSignPoint = true;
  493. Shape = "DotShape";
  494. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
  495. LineWidthMultiple = 5;
  496. annotArgs = GetStamp();
  497. break;
  498. default://图章
  499. break;
  500. }
  501. }
  502. /// <summary>
  503. /// 签名
  504. /// </summary>
  505. /// <returns></returns>
  506. private AnnotHandlerEventArgs GetSignature()
  507. {
  508. AddToPropertyPanel("SignatureAnnotProperty");
  509. return null;
  510. }
  511. /// <summary>
  512. /// 图章
  513. /// </summary>
  514. /// <returns></returns>
  515. private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
  516. {
  517. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  518. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  519. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  520. //PDFViewer.SetToolParam(stampArgs);
  521. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  522. //stampAnnotArgs.Opacity = 1;
  523. //stampAnnotArgs.StampText = "APPROVED";
  524. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  525. // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  526. stampAnnotArgs.IsContinueMode = true;
  527. stampAnnotArgs.IsSignPoint = IsSignPoint;
  528. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  529. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  530. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  531. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  532. if (stampAnnotArgs != null)
  533. stampAnnotArgsList.Add(stampAnnotArgs);
  534. //if (selectedArgs != null) {
  535. //var annot = selectedArgs[0];
  536. //if (annot != null)
  537. //{
  538. // foreach (var item in selectedArgs)
  539. // {
  540. // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
  541. // }
  542. // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
  543. // return stampAnnotArgs;
  544. //}
  545. // }
  546. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  547. return stampAnnotArgs;
  548. }
  549. public void SetStamp()
  550. {
  551. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  552. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  553. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  554. //PDFViewer.SetToolParam(stampArgs);
  555. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  556. //stampAnnotArgs.Opacity = 1;
  557. //stampAnnotArgs.StampText = "APPROVED";
  558. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  559. stampAnnotArgs.IsContinueMode = true;
  560. stampAnnotArgs.IsSignPoint = IsSignPoint;
  561. stampAnnotArgs.Opacity = FillOpacity;
  562. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  563. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  564. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  565. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  566. if (stampAnnotArgs != null)
  567. stampAnnotArgsList.Add(stampAnnotArgs);
  568. //AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  569. bool isTemplateAnnot = false;
  570. bool isSnapshotEdit = false;
  571. AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
  572. if (annotArgs != null)
  573. {
  574. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  575. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  576. PDFViewer.SetToolParam(annotArgs);
  577. isRightMenuAddAnnot = false;
  578. }
  579. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  580. if (isTemplateAnnot == false && annotArgs == null)
  581. {
  582. PDFViewer.SetMouseMode(MouseModes.PanTool);
  583. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  584. }
  585. else
  586. {
  587. if (isSnapshotEdit == true)
  588. {
  589. ShowPropertyPanel(false);
  590. isSnapshotEdit = false;
  591. }
  592. else
  593. {
  594. ShowPropertyPanel(true);
  595. }
  596. }
  597. }
  598. /// <summary>
  599. /// 手绘
  600. /// </summary>
  601. /// <param name="selectedArgs"></param>
  602. /// <returns></returns>
  603. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  604. {
  605. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  606. List<AnnotHandlerEventArgs> newSelectedArgs = new List<AnnotHandlerEventArgs>();
  607. FreehandAnnotArgs freehandArgs = null;
  608. if (selectedArgs == null || selectedArgs.Count == 0)
  609. {
  610. freehandArgs = new FreehandAnnotArgs();
  611. var annotate = Settings.Default.AppProperties.Annotate;
  612. if (annotate != null)
  613. {
  614. freehandArgs.InkColor = annotate.FreeHandColor;
  615. }
  616. else
  617. {
  618. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  619. }
  620. freehandArgs.RawPointList = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
  621. freehandArgs.Transparency = 1;
  622. freehandArgs.LineWidth = 2;
  623. if (freehandArgs != null)
  624. {
  625. selectedArgs = new List<AnnotHandlerEventArgs>();
  626. selectedArgs.Add(freehandArgs);
  627. }
  628. }
  629. else
  630. {
  631. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  632. foreach (var item in selectedArgs)
  633. {
  634. //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
  635. foreach (var point in viewContentViewModel.FillAndSign)
  636. {
  637. if ((item as FreehandAnnotArgs).PageIndex == point.Item1 && (item as FreehandAnnotArgs).AnnotIndex == point.Item2)
  638. {
  639. newSelectedArgs.Add(item);
  640. }
  641. }
  642. }
  643. freehandArgs.RawPointList = ShapePoints;
  644. freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
  645. freehandArgs.Transparency = 1;
  646. freehandArgs.LineWidth = LineWidth;
  647. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  648. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  649. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  650. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  651. annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
  652. annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  653. annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  654. AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
  655. //GetStamp();
  656. return freehandArgs;
  657. }
  658. //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  659. //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  660. //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  661. //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  662. //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
  663. return freehandArgs;
  664. }
  665. private bool ListPoint(List<List<Point>> leftpoints, List<List<Point>> rightpoints)
  666. {
  667. if (leftpoints.Count == rightpoints.Count)
  668. {
  669. if (leftpoints[0][0].X == rightpoints[0][0].X) { return true; }
  670. }
  671. return false;
  672. }
  673. /// <summary>
  674. /// 文本
  675. /// </summary>
  676. /// <param name="selectedfreetextArgs"></param>
  677. /// <returns></returns>
  678. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  679. {
  680. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  681. FreeTextAnnotArgs freetextArgs = null;
  682. TextAlignment textAlignment;
  683. if (selectedArgs == null || selectedArgs.Count == 0)
  684. {
  685. freetextArgs = new FreeTextAnnotArgs();
  686. freetextArgs.Align = TextAlignment.Left;
  687. freetextArgs.BgColor = Colors.Transparent;
  688. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  689. freetextArgs.FontColor = Colors.Black;
  690. freetextArgs.FontSize = 14;
  691. freetextArgs.Transparency = 1;
  692. freetextArgs.LineColor = Colors.Black;
  693. freetextArgs.LineWidth = 0;
  694. freetextArgs.TextContent = string.Empty;
  695. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  696. if (annotProperty != null)
  697. {
  698. freetextArgs.Align = annotProperty.TextAlign;
  699. freetextArgs.BgColor = annotProperty.BackgroundColor;
  700. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  701. freetextArgs.FontColor = annotProperty.ForgoundColor;
  702. freetextArgs.FontSize = annotProperty.FontSize;
  703. freetextArgs.Transparency = annotProperty.Opacity;
  704. freetextArgs.LineColor = annotProperty.BorderColor;
  705. freetextArgs.LineWidth = annotProperty.Thickness;
  706. freetextArgs.TextContent = annotProperty.NoteText;
  707. freetextArgs.FontWeight = annotProperty.FontWeight;
  708. freetextArgs.FontStyle = annotProperty.FontStyle;
  709. }
  710. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  711. if (align == 0)
  712. textAlignment = TextAlignment.Left;
  713. else if (align == 1)
  714. textAlignment = TextAlignment.Center;
  715. else
  716. textAlignment = TextAlignment.Right;
  717. if (freetextArgs != null)
  718. {
  719. selectedArgs = new List<AnnotHandlerEventArgs>();
  720. selectedArgs.Add(freetextArgs);
  721. }
  722. }
  723. else
  724. {
  725. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  726. textAlignment = freetextArgs.Align;
  727. }
  728. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  729. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  730. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  731. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  732. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  733. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  734. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  735. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  736. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  737. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  738. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  739. annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
  740. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
  741. return freetextArgs;
  742. }
  743. /// <summary>
  744. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  745. /// </summary>
  746. /// <param name="viewContent">对应的注释面板</param>
  747. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  748. /// <param name="annot">注释</param>
  749. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  750. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
  751. {
  752. if (annots != null && annots.Count != 0)
  753. {
  754. propertyPanel.annotlists = annots;
  755. propertyPanel.annot = annots[0];
  756. }
  757. else
  758. {
  759. propertyPanel.annotlists = null;
  760. propertyPanel.annot = null;
  761. }
  762. if (annotAttribsList != null && annotAttribsList.Count != 0 && annots != null && annots.Count != 0)
  763. {
  764. if (annots.Count > 1)
  765. {
  766. if (propertyPanel.AnnotEvents == null)
  767. propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  768. propertyPanel.AnnotEvents.Clear();
  769. foreach (var itemAnnot in annots)
  770. {
  771. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
  772. //PDFViewer.SelectAnnotation(itemAnnot.PageIndex, itemAnnot.AnnotIndex);
  773. propertyPanel.AnnotEvents.Add(eventitem);
  774. }
  775. }
  776. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
  777. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  778. {
  779. propertyPanel.AnnotEvent = annotAttribEvent;
  780. }
  781. }
  782. if (toolTag == "Freetext")
  783. {
  784. propertyPanel.SetIsTextFill(true);
  785. }
  786. else
  787. {
  788. propertyPanel.SetIsTextFill(false);
  789. }
  790. if (string.IsNullOrEmpty(viewContent) == false)
  791. {
  792. if (isUpData) { return; }
  793. if (viewContent == "ShapFillProperty") {
  794. NavigateToProperty(viewContent, propertyPanel); return; }
  795. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  796. }
  797. }
  798. private void NavigateToProperty(string btnName, AnnotPropertyPanel annotPropertyPanel)
  799. {
  800. NavigationParameters values = new NavigationParameters();
  801. values.Add(ParameterNames.PDFViewer, PDFViewer);
  802. values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  803. values.Add("Shape", Shape);
  804. values.Add("FillAndSignContentViewModel", this);
  805. regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
  806. viewContentViewModel.IsPropertyOpen = true;
  807. }
  808. /// <summary>
  809. /// 初始化按钮名称-属性面板字典
  810. /// </summary>
  811. private void InitDictionary()
  812. {
  813. btnToProperty["RbtnText"] = "TextFillProperty";
  814. btnToProperty["RbtnTick"] = "ShapFillProperty";
  815. btnToProperty["RbtnFork"] = "ShapFillProperty";
  816. btnToProperty["RbtnRectangle"] = "ShapFillProperty";
  817. btnToProperty["RbtnLine"] = "ShapFillProperty";
  818. btnToProperty["RbtnPoint"] = "ShapFillProperty";
  819. btnToProperty["RbtnDate"] = "DateFillProperty";
  820. btnToProperty["RbtnSign"] = "";
  821. }
  822. /// <summary>
  823. /// 手绘
  824. /// </summary>
  825. private void InitSelectFreeHandAnnotMenu()
  826. {
  827. var popMenu = new ContextMenu();
  828. PopMenu pop = new PopMenu(popMenu);
  829. var menuItem = new MenuItem();
  830. menuItem.Name = "FreeHandCopy";
  831. menuItem.Header = "复制";
  832. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  833. menuItem = new MenuItem();
  834. menuItem.Name = "FreeHandCut";
  835. menuItem.Header = "剪切";
  836. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  837. menuItem = new MenuItem();
  838. menuItem.Name = "FreeHandPaste";
  839. menuItem.Header = "粘贴";
  840. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  841. menuItem = new MenuItem();
  842. menuItem.Name = "FreeHandDelete";
  843. menuItem.Header = "删除";
  844. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  845. pop.AddItem(GetSeparator());
  846. menuItem = new MenuItem();
  847. menuItem.Name = "FreeHandDefault";
  848. menuItem.Header = "设置当前属性为默认值";
  849. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  850. FreeHandAnnotPopMenu = pop;
  851. }
  852. /// <summary>
  853. /// 文本
  854. /// </summary>
  855. private void InitSelectFreeTextAnnotMenu()
  856. {
  857. var popMenu = new ContextMenu();
  858. PopMenu pop = new PopMenu(popMenu);
  859. var menuItem = new MenuItem();
  860. menuItem.Name = "FreeTextCopy";
  861. menuItem.Header = "复制";
  862. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  863. menuItem = new MenuItem();
  864. menuItem.Name = "FreeTextCut";
  865. menuItem.Header = "剪切";
  866. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  867. menuItem = new MenuItem();
  868. menuItem.Name = "FreeTextPaste";
  869. menuItem.Header = "粘贴";
  870. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  871. menuItem = new MenuItem();
  872. menuItem.Name = "FreeTextDelete";
  873. menuItem.Header = "删除";
  874. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  875. pop.AddItem(GetSeparator());
  876. menuItem = new MenuItem();
  877. menuItem.Name = "FreeTextColor";
  878. menuItem.Header = "字体颜色";
  879. menuItem.Tag = "FontColor";
  880. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  881. menuItem = new MenuItem();
  882. menuItem.Name = "FreeTextColor";
  883. menuItem.Header = "填充颜色";
  884. menuItem.Tag = "FillColor";
  885. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  886. menuItem = new MenuItem();
  887. menuItem.Name = "FreeTextFontFamily";
  888. menuItem.Header = "字体";
  889. pop.AddItem(menuItem);
  890. var family = TextFont.GetFamily();
  891. foreach (var item in family)
  892. {
  893. RadioButton familyRdioBtn = new RadioButton();
  894. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  895. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  896. familyRdioBtn.Name = item.ValueStr;
  897. familyRdioBtn.Tag = item.ValueStr;
  898. familyRdioBtn.GroupName = "FontFamily";
  899. familyRdioBtn.Content = item.Content;
  900. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  901. }
  902. menuItem = new MenuItem();
  903. menuItem.Name = "FreeTextAglin";
  904. menuItem.Header = "文本对齐";
  905. pop.AddItem(menuItem);
  906. var radioButton = new RadioButton();
  907. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  908. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  909. radioButton.Name = "FreeTextAglinLeft";
  910. radioButton.Tag = "Left";
  911. radioButton.GroupName = "Aglin";
  912. radioButton.Content = "左对齐";
  913. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  914. radioButton = new RadioButton();
  915. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  916. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  917. radioButton.Name = "FreeTextAglinCenter";
  918. radioButton.Tag = "Center";
  919. radioButton.GroupName = "Aglin";
  920. radioButton.Content = "居中对齐";
  921. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  922. radioButton = new RadioButton();
  923. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  924. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  925. radioButton.Name = "FreeTextAglinRight";
  926. radioButton.Tag = "Right";
  927. radioButton.GroupName = "Aglin";
  928. radioButton.Content = "右对齐";
  929. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  930. radioButton = new RadioButton();
  931. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  932. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  933. radioButton.Name = "FreeTextAglinJustify";
  934. radioButton.Tag = "Justify";
  935. radioButton.GroupName = "Aglin";
  936. radioButton.Content = "两端对齐";
  937. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  938. menuItem = new MenuItem();
  939. menuItem.Name = "FreeHandDefault";
  940. menuItem.Header = "设置当前属性为默认值";
  941. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  942. FreeTextAnnotPopMenu = pop;
  943. }
  944. /// <summary>
  945. /// 多选注释
  946. /// </summary>
  947. private void InitSelectMultiAnnotMenu()
  948. {
  949. var popMenu = new ContextMenu();
  950. PopMenu pop = new PopMenu(popMenu);
  951. var menuItem = new MenuItem();
  952. menuItem.Name = "MultiCopy";
  953. menuItem.Header = "复制";
  954. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  955. menuItem = new MenuItem();
  956. menuItem.Name = "MultiCut";
  957. menuItem.Header = "剪切";
  958. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  959. menuItem = new MenuItem();
  960. menuItem.Name = "MultiDelete";
  961. menuItem.Header = "删除";
  962. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  963. MultiAnnotPopMenu = pop;
  964. }
  965. private Separator GetSeparator()
  966. {
  967. Separator separator = new Separator();
  968. separator.Height = 1;
  969. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  970. separator.BorderThickness = new Thickness(1);
  971. return separator;
  972. }
  973. private void BindingPDFViewerHandler()
  974. {
  975. //来自PDFViewer的响应事件
  976. if (PDFViewer != null)
  977. {
  978. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  979. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  980. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  981. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  982. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  983. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  984. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  985. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  986. }
  987. }
  988. private void UnBindingPDFViewerHandler()
  989. {
  990. if (PDFViewer != null)
  991. {
  992. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  993. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  994. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  995. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  996. }
  997. }
  998. //在注释工具的状态下,右键菜单
  999. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  1000. {
  1001. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  1002. return;
  1003. switch (e.CommandType)
  1004. {
  1005. case CommandType.Context:
  1006. if (e.AnnotEventArgsList.Count > 0)
  1007. {
  1008. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  1009. {
  1010. //绑定标记密文处右键菜单
  1011. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  1012. }
  1013. else
  1014. {
  1015. if (e.AnnotEventArgsList.Count == 1)
  1016. {
  1017. var selectedAnnot = e.AnnotEventArgsList[0];
  1018. switch (selectedAnnot.EventType)
  1019. {
  1020. case AnnotArgsType.AnnotFreehand:
  1021. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1022. break;
  1023. case AnnotArgsType.AnnotFreeText:
  1024. e.PopupMenu= FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1025. break;
  1026. }
  1027. }
  1028. else
  1029. {
  1030. bool isHigh = true;//是否为高亮
  1031. foreach (var item in e.AnnotEventArgsList)
  1032. {
  1033. if (isHightAnnot(item) == false)
  1034. {
  1035. isHigh = false;
  1036. break;
  1037. }
  1038. }
  1039. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  1040. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  1041. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  1042. }
  1043. }
  1044. if (e.PopupMenu != null)
  1045. {
  1046. e.Handle = true;
  1047. }
  1048. }
  1049. else
  1050. {
  1051. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  1052. {
  1053. if (e.PopupMenu != null)
  1054. {
  1055. e.Handle = true;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. e.PopupMenu = ViewerContextMenu(sender);
  1061. if (e.PopupMenu != null)
  1062. {
  1063. e.Handle = true;
  1064. }
  1065. }
  1066. }
  1067. break;
  1068. }
  1069. }
  1070. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1071. {
  1072. if (e != null && e.DrawContext != null)
  1073. {
  1074. Rect hoverRect = new Rect(
  1075. e.PaintRect.Left - 2,
  1076. e.PaintRect.Top - 2,
  1077. e.PaintRect.Width + 4,
  1078. e.PaintRect.Height + 4);
  1079. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1080. hoverPen.DashStyle = DashStyles.Dash;
  1081. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1082. //Todo:目前ComPDFKit.Viewer没有e.Annot参数
  1083. //便签,显示ToolTip内容
  1084. //if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  1085. //{
  1086. // if (PDFViewer.ToolTip == null)
  1087. // {
  1088. // var content = e.Annot.GetContent();
  1089. // if (string.IsNullOrEmpty(content) == false)
  1090. // {
  1091. // ToolTip TipChild = new ToolTip();
  1092. // TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  1093. // TipChild.MaxWidth = 246;
  1094. // TipChild.Content = content;
  1095. // TipChild.Visibility = Visibility.Visible;
  1096. // TipChild.IsOpen = true;
  1097. // TipChild.Placement = PlacementMode.Right;
  1098. // var rec = e.Annot.GetRect();
  1099. // TipChild.PlacementRectangle = new Rect(rec.left, rec.top, rec.right, rec.bottom);
  1100. // TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1101. // TipChild.Placement = PlacementMode.MousePoint;
  1102. // PDFViewer.ToolTip = TipChild;
  1103. // oldRect = hoverRect;
  1104. // PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1105. // PDFViewer.MouseMove += PDFViewer_MouseMove;
  1106. // return;
  1107. // }
  1108. // }
  1109. //}
  1110. }
  1111. CloseAnnotToolTip();
  1112. }
  1113. private Rect oldRect = new Rect(0, 0, 0, 0);
  1114. private void CloseAnnotToolTip()
  1115. {
  1116. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1117. {
  1118. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1119. oldTips.IsOpen = false;
  1120. oldTips.Visibility = Visibility.Collapsed;
  1121. PDFViewer.ToolTip = null;
  1122. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1123. oldRect = new Rect(0, 0, 0, 0);
  1124. }
  1125. }
  1126. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1127. {
  1128. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1129. {
  1130. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1131. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1132. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1133. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1134. {
  1135. CloseAnnotToolTip();
  1136. }
  1137. }
  1138. }
  1139. private ContextMenu ViewerContextMenu(object sender)
  1140. {
  1141. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1142. ViewerContextMenu_Loaded(contextMenu, sender);
  1143. return contextMenu;
  1144. }
  1145. private void ViewerContextMenu_Loaded(object sender, object e, Visibility visibility = Visibility.Collapsed)
  1146. {
  1147. ContextMenu contextMenu = sender as ContextMenu;
  1148. if (contextMenu.Items.Count > 0)
  1149. {
  1150. int index = PDFViewer.CurrentIndex;
  1151. //检测是否已存在相同数据
  1152. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  1153. foreach (var item in contextMenu.Items)
  1154. {
  1155. if (item is Separator separator)
  1156. {
  1157. separator.Visibility = visibility;
  1158. }
  1159. if (item is MenuItem menuItem1)
  1160. {
  1161. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  1162. //{
  1163. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  1164. //}
  1165. switch (menuItem1.Tag.ToString())
  1166. {
  1167. case "Paste":
  1168. //粘贴
  1169. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  1170. //{
  1171. // menuItem1.IsEnabled = false;
  1172. // menuItem1.Opacity = 0.5;
  1173. //}
  1174. //else
  1175. //{
  1176. // menuItem1.IsEnabled = true;
  1177. // menuItem1.Opacity = 1;
  1178. //}
  1179. menuItem1.CommandTarget = (UIElement)e;
  1180. menuItem1.Command = ApplicationCommands.Paste;
  1181. break;
  1182. case "AddAnnotation":
  1183. menuItem1.Visibility = visibility;
  1184. break;
  1185. case "HiddenAnnot":
  1186. menuItem1.Visibility = visibility;
  1187. break;
  1188. case "DisplayAnnot":
  1189. menuItem1.Visibility = visibility;
  1190. break;
  1191. case "AddBookMark":
  1192. menuItem1.Visibility = visibility;
  1193. break;
  1194. case "DelBookMark":
  1195. menuItem1.Visibility = visibility;
  1196. break;
  1197. case "ToolMode":
  1198. menuItem1.Visibility = visibility;
  1199. break;
  1200. case "ReadModel":
  1201. menuItem1.Visibility = visibility;
  1202. break;
  1203. case "UnReadModel":
  1204. menuItem1.Visibility = visibility;
  1205. break;
  1206. case "ViewZoom":
  1207. menuItem1.Visibility = visibility;
  1208. break;
  1209. case "PageDisplay":
  1210. menuItem1.Visibility = visibility;
  1211. break;
  1212. case "Select":
  1213. menuItem1.Click -= Select_Click;
  1214. menuItem1.Click += Select_Click;
  1215. break;
  1216. case "Print":
  1217. menuItem1.Command = viewContentViewModel.PrintCommand;
  1218. break;
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }
  1224. private void Select_Click(object sender, RoutedEventArgs e)
  1225. {
  1226. if (viewContentViewModel.OpenBOTA == false)
  1227. {
  1228. viewContentViewModel.OpenBOTA = true;
  1229. }
  1230. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1231. if (isBook == false)
  1232. {
  1233. bOTAContent.TabItemSearch.IsSelected = true;
  1234. }
  1235. }
  1236. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1237. {
  1238. bool isTabItem = false;
  1239. bOTAContentViewModel = null;
  1240. bOTAContent = null;
  1241. if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  1242. {
  1243. var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
  1244. var model = views.FirstOrDefault(q => q is BOTAContent);
  1245. if (model is BOTAContent bOTAContent1)
  1246. {
  1247. bOTAContent = bOTAContent1;
  1248. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1249. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1250. {
  1251. isTabItem = true;
  1252. }
  1253. }
  1254. //foreach (var item in views)
  1255. //{
  1256. // if (item is BOTAContent bOTAContent1)
  1257. // {
  1258. // bOTAContent = bOTAContent1;
  1259. // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1260. // if (bOTAContentViewModel.CurrentBar == tabItemText)
  1261. // {
  1262. // isTabItem = true;
  1263. // break;
  1264. // }
  1265. // }
  1266. //}
  1267. }
  1268. return isTabItem;
  1269. }
  1270. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  1271. {
  1272. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  1273. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  1274. annot.EventType == AnnotArgsType.AnnotHighlight ||
  1275. annot.EventType == AnnotArgsType.AnnotStrikeout
  1276. )
  1277. {
  1278. return true;
  1279. }
  1280. else
  1281. {
  1282. return false;
  1283. }
  1284. }
  1285. //注释编辑事件
  1286. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1287. {
  1288. if (e != null && e.Count > 0)
  1289. {
  1290. for (int i = 0; i < e.Count; i++)
  1291. {
  1292. AnnotEditEvent editEvent = e[i];
  1293. switch (editEvent.EditAction)
  1294. {
  1295. case ActionType.Add:
  1296. int pageindex = editEvent.PageIndex;
  1297. int annotindex = editEvent.AnnotIndex;
  1298. viewContentViewModel.FillAndSign.Add(new Tuple<int,int>(pageindex, annotindex));
  1299. PDFViewer.SelectAnnotation(pageindex, annotindex);
  1300. break;
  1301. }
  1302. }
  1303. }
  1304. }
  1305. //选中和非选中注释,右键菜单
  1306. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1307. {
  1308. if (e != null)
  1309. {
  1310. var annot = e.AnnotItemsList[0];
  1311. if (annot != null)
  1312. {
  1313. if (e.AnnotItemsList.Count == 1)
  1314. {
  1315. //IsEdit = false;
  1316. //IsAnnotCreateReset:是否为创建注释的状态
  1317. if (e.IsAnnotCreateReset == false)
  1318. {
  1319. GetSelectedAnnots(e);
  1320. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  1321. //PDFViewer.SetToolParam(annot);
  1322. }
  1323. else
  1324. {
  1325. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  1326. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  1327. annot.EventType != AnnotArgsType.AnnotUnderline &&
  1328. annot.EventType != AnnotArgsType.AnnotHighlight &&
  1329. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  1330. annot.EventType != AnnotArgsType.AnnotLink &&
  1331. annot.EventType != AnnotArgsType.AnnotFreehand &&
  1332. annot.EventType != AnnotArgsType.AnnotSticky
  1333. )
  1334. {
  1335. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  1336. {
  1337. foreach (var item in ToolExpandDict)
  1338. {
  1339. if (item.Value == e.AnnotItemsList[0].EventType)
  1340. {
  1341. annot = null;//新建注释时,回到默认值
  1342. FindAnnotTypeKey(item.Key, ref annot);
  1343. break;
  1344. }
  1345. }
  1346. }
  1347. }
  1348. //else
  1349. //PDFViewer.SetToolParam(annot);
  1350. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  1351. if (isRightMenuAddAnnot)
  1352. {
  1353. ShowPropertyPanel(false);
  1354. }
  1355. else
  1356. {
  1357. ShowPropertyPanel();
  1358. }
  1359. }
  1360. }
  1361. else
  1362. {
  1363. bool isDifferentAnnotTyle = false;
  1364. var lastAnnot = annot;
  1365. foreach (var item in e.AnnotItemsList)
  1366. {
  1367. if (lastAnnot.EventType != item.EventType)
  1368. {
  1369. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  1370. {
  1371. lastAnnot = item;
  1372. continue;
  1373. }
  1374. lastAnnot = item;
  1375. isDifferentAnnotTyle = true;
  1376. break;
  1377. }
  1378. }
  1379. if (isDifferentAnnotTyle)
  1380. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1381. else
  1382. GetSelectedAnnots(e);
  1383. }
  1384. }
  1385. }
  1386. else
  1387. {
  1388. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1389. }
  1390. }
  1391. //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1392. //{
  1393. // if (e != null && e.Count > 0)
  1394. // {
  1395. // for (int i = 0; i < e.Count; i++)
  1396. // {
  1397. // AnnotEditEvent editEvent = e[i];
  1398. // switch (editEvent.EditAction)
  1399. // {
  1400. // case ActionType.Add:
  1401. // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1402. // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  1403. // {
  1404. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1405. // if (viewModel != null)
  1406. // {
  1407. // int pageindex = editEvent.PageIndex;
  1408. // int annotindex = editEvent.AnnotIndex;
  1409. // viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1410. // }
  1411. // }
  1412. // break;
  1413. // case ActionType.Del:
  1414. // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1415. // if (isTabItemAnnotation)
  1416. // {
  1417. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1418. // if (viewModel != null)
  1419. // {
  1420. // int pageindex = editEvent.PageIndex;
  1421. // int annotindex = editEvent.AnnotIndex;
  1422. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  1423. // }
  1424. // }
  1425. // break;
  1426. // case ActionType.Modify:
  1427. // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1428. // if (bOTAContent.TabItemAnnotation.IsSelected)
  1429. // {
  1430. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1431. // if (viewModel != null)
  1432. // {
  1433. // int pageindex = editEvent.PageIndex;
  1434. // int annotindex = editEvent.AnnotIndex;
  1435. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  1436. // }
  1437. // }
  1438. // break;
  1439. // case ActionType.TextEdit:
  1440. // break;
  1441. // default:
  1442. // break;
  1443. // }
  1444. // }
  1445. // }
  1446. //}
  1447. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  1448. {
  1449. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  1450. annot.EventType == AnnotArgsType.AnnotSquare ||
  1451. annot.EventType == AnnotArgsType.AnnotLine
  1452. )
  1453. {
  1454. return true;
  1455. }
  1456. else
  1457. {
  1458. return false;
  1459. }
  1460. }
  1461. private void GetSelectedAnnots(AnnotAttribEvent e)
  1462. {
  1463. IsEdit = true;
  1464. var annot = e.AnnotItemsList[0];
  1465. switch (annot.EventType)
  1466. {
  1467. case AnnotArgsType.AnnotFreeText:
  1468. GetFreetext(e.AnnotItemsList);
  1469. break;
  1470. case AnnotArgsType.AnnotFreehand:
  1471. GetFreehand(e.AnnotItemsList);
  1472. break;
  1473. }
  1474. }
  1475. private void ShowPropertyPanel(bool show = true)
  1476. {
  1477. viewContentViewModel.IsPropertyOpen = show;
  1478. }
  1479. #region Navigation
  1480. public bool IsNavigationTarget(NavigationContext navigationContext)
  1481. {
  1482. return true;
  1483. }
  1484. public void OnNavigatedFrom(NavigationContext navigationContext)
  1485. {
  1486. UnBindingPDFViewerHandler();
  1487. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1488. ViewerContextMenu_Loaded(contextMenu, null, Visibility.Visible);
  1489. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1490. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1491. ShowPropertyPanel(false);
  1492. }
  1493. public void OnNavigatedTo(NavigationContext navigationContext)
  1494. {
  1495. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1496. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1497. BindingPDFViewerHandler();
  1498. HookShapeIsCheck = true;
  1499. InitFillAndSignProperty();
  1500. InitCheckedEvent("RbtnTick");
  1501. IsEdit = false;
  1502. }
  1503. #endregion
  1504. }
  1505. }