FillAndSignContentViewModel.cs 71 KB

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