FillAndSignContentViewModel.cs 72 KB

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