FillAndSignContentViewModel.cs 72 KB

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